[FX.php List] Validating hidden input from checkbox with Javascript

Kim Hawksworth kim.hawksworth at osumc.edu
Sun Oct 22 23:00:15 MDT 2006


 Greetings Everyone,

I¹m trying to use javascript to validate hidden input elements in which the
values come from radio buttons and checkboxes.  I need to validate that at
least one checkbox has been checked when a particular radio button is
selected.  The value of the radio button is also submitted with a hidden
form element.

Here¹s my input code:

<form name="activateConsult" action="/nss/newConsult.php" method="post"
onSubmit="return validate_form()">
<input type=²hidden² name=²en_trial² value=²<?php echo
$recordData[Œen_trial¹][0]; ?>²>
<input type=²hidden² name=²en_trial_yes[]² value=²<?php echo
$recordData[Œen_trial_yes¹][0]; ?>²>

The en_trial value comes from the radio button and and ³en_trial_yes[]²
value comes from the checkboxes.

My javascript validate_form() function looks like this:

var en_trial = document.activateConsult.en_trial[0];  //selected radio
button is in the first position of the array
var en_trial_yes = document.activateConsult.['en_trial_yes[]'];  //creates a
variable javascript will recognise

if (document.activateConsult.en_trial.value == "Yes, unsuccessful" &&
document.activateConsult.en_trial_yes.value == "") {

alert ("A reason must be indicated why the enteral trial was unsuccessful
before the consult can be activated!");
return false;
}


The first part of the script works fine.  It¹s when I add the code after the
&& that doesn¹t work.  I¹m sure it¹s a syntax issue.  Any ideas how I can
get this to work?

Thanks for your help.

-- 
Kim D. Hawksworth, R.Ph., Web Manager
Department of Pharmacy
The Ohio State University Health System

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20061023/57538b9e/attachment.html


More information about the FX.php_List mailing list