permaculture playing cards*
The moose likes JSP and the fly likes how to take javascript values into insert query in jsp? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how to take javascript values into insert query in jsp?" Watch "how to take javascript values into insert query in jsp?" New topic
Author

how to take javascript values into insert query in jsp?

neha agg
Greenhorn

Joined: Sep 30, 2012
Posts: 4
while(rs.next())
{

String id=rs.getString("id");
String question=rs.getString("question");
String option1=rs.getString("option1");
String option2=rs.getString("option2");
String option3=rs.getString("option3");
String option4=rs.getString("option4");
String answer=rs.getString("answer");
%>

<form name="f1">
<%= id %> <%= question %> <br/>
<input type="radio" name="op1" id="op11" value="<%= option1%>" /> <%= option1 %> <br/>
<input type='radio' name="op1" value="<%= option2%>" /> <%= option2 %> <br/>
<input type='radio' name="op1" value="<%= option3%>" /> <%= option3 %> <br/>
<input type='radio' name="op1" value="<%= option4%>" /> <%= option4 %><br/>
<input type='submit' name='btn' value='click' onclick="call()"/>
</form>


<script>
function call()
{

var selection = document.f1.op1;

for (var i=0; i<selection.length; i++)
if (selection[i].checked == true)
document.write(selection[i].value); //how to take this value in inser query in jsp



System.out.println("inserted");

}


</script>



<%


break;

}

please help!!!
document.write(selection[i].value); //how to take this value in inser query in jsp
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60059
    
  65

You can't. The JSP executes on the server long before the JavaScript executes on the client after the page is sent to the browser. Please read this JspFaq entry for more info.

Also, using Java code in a JSP is a poor and obsolete practice from over 10 years ago. Please read this JspFaq entry.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to take javascript values into insert query in jsp?
 
Similar Threads
Inter Frame communication in quiz application
JSP Pagination not working
Struts 2 <s:submit action > and javascript help
Show a hidden text field
Comparing value of radio button against answer from the database