[FX.php List] RE: Re: Problem with Javascript validating
Kim Hawksworth
Kim.Hawksworth at osumc.edu
Fri Jul 28 11:03:33 MDT 2006
Andrew, Thank you very much! Both methods resolve the issue. I chose to
put the checkboxes into a variable (your relavation) in order to make the
code a bit more compact.
Thanks again for your help.
--Kim
--
Kim David Hawksworth, R.Ph., Web Manager
The OSUMC Dept. of Pharmacy
410 W. 10Th Ave, Room 368 Doan
Ph# (614) 293-3765
Pager# (614) 730-8143
Email: kim.hawksworth at osumc.edu
---------------
Date: Fri, 28 Jul 2006 09:55:59 -0500
From: "Andrew Denman" <adenman at tmea.org>
Subject: RE: [FX.php List] Problem with Javascript validating
Checkboxes
To: "'FX.php Discussion List'" <fx.php_list at mail.iviking.org>
Message-ID: <00eb01c6b255$f0003eb0$c864a8c0 at tmea.org>
Content-Type: text/plain; charset="us-ascii"
The code won't work because to the javascript, 'en_trial_yes[]' is the name
of the checkboxes. Only PHP recognizes the [] in the name and creates an
array from the form. The problem is you cannot use [] in javascript without
escaping it, so this is the only way I've found to get to the checkboxes:
1. Place the form in a variable ('frm' below)
2. Reference the checkboxes with this: frm['en_trial_yes[]']
3. You can then use this name just like you would any other variable
<!-- Code -->
var frm = document.newConsult;
var IsEnteralReason = "";
for (var i = 0; i < frm['en_trial_yes[]'].length; i++) {
if (frm['en_trial_yes[]'][i].checked) {
IsEnteralReason = frm['en_trial_yes[]'][i].value;
}
}
if (IsEnteralReason == "") {
alert ("Please indicate the reason(s) the enteral trial was
unsuccessful!");
return false;
}
<!-- End Code -->
I had a revelation while typing this. I haven't tested it yet, but this
might/should work:
1. Put the checkboxes in a variable (ie: var en_trial =
document.newConsult['en_trial_yes[]'];)
2. And then use en_trial as the checkbox name in javascript (ie;
IsEnteralReason = en_trial[i].value;).
If you try this, let us know how it turns out.
Andrew Denman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20060728/4482c0f9/attachment.html
More information about the FX.php_List
mailing list