Click to See Complete Forum and Search --> : Populate a hidden field w/JavaScript


skir
01-23-2006, 12:27 PM
I have the following code:

function checkForm(ACH) {
form = document.ACH
if (form.new_customer.value != "yes") {
var response = confirm ("To save typing in the future, do you wish to save\n this customer's account information?")
//alert (response)
if (response==true){
form.save_cdb.value="yes";
}
}

The hidden field is simply <input type="hidden" name="save" value="">

It only works if I change the field 'save_cdb' to a regular text field. I need it hidden though. I can access the hidden field by hardcoding a value and then doing an alert on it, but cannot set a value for this field.

bschaettle
02-13-2006, 09:27 AM
You mistyped the name field of your <input> tag.

You have <input type="hidden" name="save" value="">

Should be <input type="hidden" name="save_cdb" value="">

Also, are you doing your form-checking using the "onSubmit" event handler? Here's how I do form-checking:


<SCRIPT Language="JavaScript">
function ProcessFormElements(f) {
if (f) {
if (f.elements['new_customer'].value != "yes") {
var response = confirm("question?");
if (response) {
f.elements['save_cdb'].value = "yes";
}
}
}
return true // if you return false, then the form is not submitted.
}
</SCRIPT>
...
<BODY>
...
<FORM
NAME="form1"
ID="form1"
METHOD=POST
ONSUBMIT="return ProcessFormElements(this)"
ACTION="http://www.MyDomain.com/folder/My_Form_Handler.htm">
<input type="hidden" name="save_cdb" value="">
...
</FORM>
...
</BODY>