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

Andrew Denman adenman at tmea.org
Mon Oct 23 11:48:24 MDT 2006


The problem is that document.activateConsult.['en_trial_yes[]'] is an array
of all of the inputs with that name.  If you only have one, you should use
document.activateConsult.['en_trial_yes[]'][0].  If you have more than one,
you will have to loop through them to see the value of each one.  Here's a
modified bit of code I use:
 
for(i=frm['en_trial_yes[]'].length-1; i>-1;
i--){if(!frm['en_trial_yes[]'][i].checked){/* Send Error Code */}}
 
Andrew Denman
  _____  

From: fx.php_list-bounces at mail.iviking.org
[mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of Kim Hawksworth
Sent: Monday, October 23, 2006 12:00 AM
To: fx.php_list at mail.iviking.org
Subject: [FX.php List] Validating hidden input from checkbox with Javascript
 
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/131df37d/attachment.html


More information about the FX.php_List mailing list