View Full Version : semi colon in javascript validation
babuvt
02-13-2005, 04:20 PM
Hi,
I have a asp line as
<Select name='cbo27;28'>
...........
...........
</Select>
I need to write a javascript to validate if the combo's selected index is 0.
if document.all.cbo27:28.selectedIndex == 0
alert('Please select a value');
else
frmform.submit();
How can I validate it escaping the semicolon? Please help.... :confused:
codegoboom
02-13-2005, 04:49 PM
Ideally, just give it an external <label>, instead using the option as a label.
some other ways:
document.all.item("name")
document.getElementsByName("name")[0] (or item(0))
give it an id... document.getElementById("name")
Bear in mind that semicolons probably shouldn't be used in the first place, according to the spec:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
babuvt
02-14-2005, 07:44 AM
Hey,
It rocks!!! :thumbsup: Thanks a lot.....
I understand that ; should not be used but unfortunately we have com+ component generating this HTML/asp code... We dont have the source code of COM+ to redesign it and hence even adding a ID to it is not feasible.
I have used if (document.all.item("cbo27;28").selectedIndex==0)
and it works great.
Hats off to you!!! :)
unfortunately we have com+ component generating this HTML/asp code... We dont have the source code of COM+ to redesign it
it's a right royal bummer when you have to deal with shoddy thirdy party code. but it's far worse when you have to sort out code written by so-called experts within your own company. that's far worse.
sorry, felt like venting my spleen ... :frown:
glenngv
02-14-2005, 10:16 AM
Hey,
It rocks!!! :thumbsup: Thanks a lot.....
I understand that ; should not be used but unfortunately we have com+ component generating this HTML/asp code... We dont have the source code of COM+ to redesign it and hence even adding a ID to it is not feasible.
I have used if (document.all.item("cbo27;28").selectedIndex==0)
and it works great.
Hats off to you!!! :)
See the square bracket notation link in my sig to see the cross-browser ways of accessing fields as well as variables and properties of objects.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.