• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Javascript coding problem for two submit buttons in one form

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

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

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>
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Set the form's method to POST (form method="POST"). It's GET by default.
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your help Satou kurinosuke. But where do i Set the form's method to POST (form method="POST").
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Satou kurinosuke. But when i try it the values do not get passed onto to the database for storage. I'm using jsp and mysql.
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vanan saravanan:
Thank you Satou kurinosuke. But when i try it the values do not get passed onto to the database for storage. I'm using jsp and mysql.



First, get values from request parameters and print it on console or screen and see if you are getting the right values then perform DB operation.

Post your code if you can.

 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you rathi ji for your help.

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();
%>
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't recall talking about "post", but about "POST"
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tried using "POST". Does not seem to work too. Database value is "null"
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vanan saravanan:
Thank you rathi ji for your help.

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();
%>



... and the same code work for GET request but not for POST.

I am just guessing, close your statement before connection closing and did you check (print) the value before sending to DB?
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satou kurinosuke:
I don't recall talking about "post", but about "POST"



Satou, I think, HTML is not case sensitive then why this... :roll:
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do i (print) the value before sending to DB...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Satou, I think, HTML is not case sensitive then why this...


Because I'm a fool and I don't like smallcase POST
Sorry for the useless post (<-- this post is lowercase, ok )
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by vanan saravanan:
how do i (print) the value before sending to DB...



out.println() should do.
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Got the problem solved, thank you to all who helped.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you could bring some light on what the problem was
 
vanan saravanan
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I changed the script to something else. Its easier and it works. The script as follows. Thank you once again to all who helped.


<input name="b1" type="button" value="submit1"
onclick ="this.form.action ='test1.jsp';this.form.submit()">

<input name="b2" type="button" value="submit2"
onclick="this.form.action ='test2.jsp';this.form.submit()">
 
You can't have everything. Where would you put it?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic