| Author |
How to set a form field using javascript
|
Chris Wang
Ranch Hand
Joined: Jan 13, 2004
Posts: 34
|
|
I have a jsp and there are some fields in the form. The fields are dynamical, such as question_1, question_2, question_3, ..., question_i, in which 'i' is dynamical. Beside each fields I suppose to put a 'default' button. When user click the button, the field can be set a default value. I think i can use a javascript function to realize it. The function could be like this: function doDefault_questionBreak(defaultvalue,i){ document.forms[0].question_i.value = defaultvalue; } How can i use the parameter 'i' to set a value(defaultvalue) to its field (question_i)? Maybe it's a javascript question. Thank in advance.
|
 |
Kishore Dandu
Ranch Hand
Joined: Jul 10, 2001
Posts: 1934
|
|
Using Java Script, u will be able to change the value inside a field on the form(gui), but you can not change the actual serverside value. You can use the server side value though. I don't know if that answered your question. Kishore.
|
Kishore
SCJP, blog
|
 |
Bear Bibeault
Author and opinionated walrus
Marshal
Joined: Jan 10, 2002
Posts: 50677
|
|
Please be sure to place question in the appropriate forum. Since this is a Javascript question, this is better asked in the HTML/Javascript forum. Moving to that forum. thanks, bear JSP Forum Bartender
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Eric Pascarello
author
Rancher
Joined: Nov 08, 2001
Posts: 15003
|
|
Basic Idea: document.formName["standardName_" + variable].value = "BLAH";
|
 |
Chris Wang
Ranch Hand
Joined: Jan 13, 2004
Posts: 34
|
|
Hi Kishore, Thank your response. When user click the 'default' button, the field is set to a value, it is the same as user inputs a value. After that the form is submit and the server can get the value. But my question is how to write the field name question_i? 'i' is a parameter, absolutely i can't write as 'question_i', so what is the correct way? Thanks, Chris
|
 |
Chris Wang
Ranch Hand
Joined: Jan 13, 2004
Posts: 34
|
|
Eric, Thank you very much. That's what i want. I solved the problem! Regards, Chris
|
 |
 |
|
|
subject: How to set a form field using javascript
|
|
|