faqts : Computers : Programming : Languages : Java

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

15 of 22 people (68%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

how will you assign javascript variable to java variable?

Oct 28th, 2007 05:19
Sridhar Paidi, shanmugakumar arumugasamy,


Javascript is client side processing. So java program in an applicaton 
server can't read the variables. Java script startes working once the 
HTML code is generated by the servlet and is send to the browser.

However if you know what values you will need in a servlet, you can 
pass the vaues to the servlet as a hidden value. Just use Javascript 
and put the value in a hidden textbox and submit the page.


<script type="text/javascript">
function beforeSubmit()
{
var d = new Date() // Say you want to use variable d in the javacode
document.forms[0].hiddentextbox.value= d
document.forms[0].submit()
}
</script>