Click to See Complete Forum and Search --> : pass value from javascript to jsp


glotsa
02-24-2003, 02:58 AM
i have found some difficulties and would like to seek help.

i am making a jsp which is a questionnaire for user to input score through a textfield. After user fill in the score, there is an onChange event evolving and then it will call a javascript function. This function is to getting the score input by user in order to calculate the score that the user can gain for the question. The gain score will be displayed on score column.

After user click "save" button, a confirmation page will be displayed. In this page, i would like to display the score input by user and also the score gained by user.

However, i can only get the score input by user, as i can use request.getParameter("textfieldname"). I would like to know how to get the score which is calculated by javascript function?? I have used a variable to store the score in the function, but how the confimation page (jsp) can get this variable value??

AdamGundry
02-24-2003, 03:14 AM
You could create a hidden field, like this:
<input type="hidden" name="score" value="">

Then put this code in your form tag:
<form onSubmit="score.value = CalcScore()">

This creates a hidden field called score which contains the result of the CalcScore() function - you should be able to modify it to fit your code. Then (I presume, as I don't know JSP) you can access the value with request.getParameter("score").

Hope this helps

Adam

glotsa
02-24-2003, 03:46 AM
but in my questionniare, if there are three textfields for inputting score, then three scores will be calculated by the javascript function. (It means that different scores for different questions)
In the function, i have used an array to store the score that can be gain by user. Then how can i do??