/    Sign up×
Community /Pin to ProfileBookmark

Javascript coding problem for two submit buttons in one form

Hi, i have two submit buttons in one form. Each goes to a different jsp page. The script i have works fine, the problem is whatever values i entered into the form is now visible in the address bar for example

[url]http://localhost:8080/test1.jsp?name=testing[/url]

How do i ensure that the values which i enter into the form is not shown in the address bar. This is my script.

<script language=”JavaScript”><!–
function sendForm(action,encoding) {
if (document.images) {
document.registerForm.action = action;
document.registerForm.encoding = encoding;
}
return true;
}
//–></script>

<form name=”registerForm”>
<input type=”text” name=”myText” value=”some text”>
<input type=”submit” value=”Submit1″ onClick=”sendForm(‘test1.jsp’,’text/plain’)”>
<input type=”submit” value=”Submit2″ onClick=”sendForm(‘test2.jsp’,’text/plain’)”>
</FORM>

to post a comment
JavaScript

16 Comments(s)

Copy linkTweet thisAlerts:
@maheshcsharmaOct 10.2006 — u cannnot have 2 submit buttons for the same form
Copy linkTweet thisAlerts:
@nitro2k01Oct 10.2006 — The obious answer would be frameset cloaking. But why do you want to hide the address from the user?
Copy linkTweet thisAlerts:
@lvsaintauthorOct 10.2006 — Not hiding the address from the user but the information stored in the form from the user. This is the page i'm going to http://localhost:8080/test1.jsp. But in the address bar it also shows ?name=testing. Which is the data in the form. I want to ensure that the user does not see what being passed into the database
Copy linkTweet thisAlerts:
@nitro2k01Oct 10.2006 — Add [b]method="post"[/b] to the form. This might need some changes in the server-side code to work. In PHP it means you use [b]$_POST['field'][/b] instead of [b]$_GET['field'][/b]. In jsp I have no clue what changes to make. (Perhaps none! (: )

But a little security consideration. I get a feelign that you could hack the database easily with these arguments. It's very easy to manipulate what is being sent to the server. Check once and thrice this won't open any security holes.
Copy linkTweet thisAlerts:
@lvsaintauthorOct 10.2006 — Thank you that works, but my values from the filelds are not passed onto the database...

Using jsp and mysql.
Copy linkTweet thisAlerts:
@nitro2k01Oct 10.2006 — Well, you're done on the client-side. I suggest you go to [url=http://www.webdeveloper.com/forum/forumdisplay.php?f=31]the Java part of the forum[/url] and ask something like: "How do I read post data from an HTML form in JSP?"
Copy linkTweet thisAlerts:
@nithin16184Oct 10.2006 — Put the data to be passes in a hidden variable and then submit the form

i.e <input type=hidden name=strHidden>

onclick="javascript:fnadd('youdata')

javascript:fnadd(youdata)

{

document.[formname].strHidden=youdata;

document.[formname].submit;


}


in the next jsp

you can get it from request.getParameter("strHidden");


i am not very sure ..may be you can give a try.

happy coding ?
Copy linkTweet thisAlerts:
@nitro2k01Oct 10.2006 — nithin16184: [b]<input type="hidden" />[/b] just means the code is hidden from visual appearance on the page, not that it will be hidden from the address bar. Besides your code is so full of errors that it almost makes me cry.
Copy linkTweet thisAlerts:
@nithin16184Oct 10.2006 — oh sorry ...

i just typed it in hurry

would post more carefully next time.

thanks.
Copy linkTweet thisAlerts:
@nithin16184Oct 10.2006 — besides have u tried havin "method=post" in <form> tag

in the next jsp you can get the value by using

request.getParameter("myText");

which will return you the string.
Copy linkTweet thisAlerts:
@lvsaintauthorOct 10.2006 — When i use the script without method="post" the values are saved into database with no problems. When i add method="post" into the script the database receives null value. Here is the script for my jsp page. The javascript is posted in the first post. Thank you all for your valuable help.

<%

Statement stm=null;

stm= con.createStatement();

String Childname = request.getParameter("name");

String insertChildname = "insert into ds (Childic) values ('"+Childname+"')";

stm.executeUpdate(insertChildname);

con.close();

%>
Copy linkTweet thisAlerts:
@nitro2k01Oct 10.2006 — My fair guess is that you have the text doGet somehwere in your script. Replace it with doPost and try again.
Copy linkTweet thisAlerts:
@nithin16184Oct 10.2006 — <%

Statement stm=null;

stm= con.createStatement();

String Childname = request.getParameter("myText");// only change here!

String insertChildname = "insert into ds (Childic) values ('"+Childname+"')";

stm.executeUpdate(insertChildname);

con.close();

%>


think this should help !
Copy linkTweet thisAlerts:
@lvsaintauthorOct 10.2006 — String Childname = request.getParameter("myText");// only change here!

Tried the above still does not work...
Copy linkTweet thisAlerts:
@lvsaintauthorOct 11.2006 — Is there any other script that will enable me too have two submit buttons in one form...
Copy linkTweet thisAlerts:
@lvsaintauthorOct 11.2006 — Got the problem solved, thank you to all who helped.
×

Success!

Help @lvsaint spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...