| | |
|
|
|
JS question--what is wrong with my code? |
| message from middletree on 15 Jul 2004 |
It's an ASP intranet page, but I put up and HTML version at
http://www.middletree.net/sample.html
Find the listbox labeled Original Caller Name, with a checkbox near it.
I have that checkbox checked when the page loads, and when it remains
checked upon page submission, it should throw a javascript error if you
don't select one of the names in there. The good news is, it gives you the
error msg box. The bad news is, it still forwards you to the next page
(which happens to be absent in my example; sorry)
Thing is, I don't want it to submit; I want it to return false. That's where
my question lies.
Here's my JS code for that error msg(don't worry about the
ExternalContactID; long story)
if (frm.source.checked == true) {
if (frm.InternalContactID.value == "")
{
alert("Please select the internal person who called with this
problem.");
frm.InternalContactID.focus();
return (false);
}
else {
if (frm.ExternalContactID.value == "SELECT")
{
alert("Please select the person who called with this problem.");
frm.ExternalContactID.focus(); return (false);
|
| Mick White replied to middletree on 15 Jul 2004 |
if (frm.source.checked){
if(!frm.InternalContactID.value) {
alert("Please select the internal person who called with this problem.");
frm.InternalContactID.focus();
return false;
}
// no "else" statement needed after "return"
if (!frm.ExternalContactID.selectedIndex) {
alert("Please select the person who called with this problem.");
frm.ExternalContactID.focus();
return false;
}
//I'm assuming that "ExternalContactID" is a select menu, if its
selectedIndex is zero, it means that the header (e.g. "Please Select")
is selected.
if (!frm.ExternalContactID.selectedIndex)
is the same as:
if (frm.ExternalContactID.selectedIndex==0)
Mick
middletree wrote:
|
|
Archived message: JS question--what is wrong with my code? (Macromedia Dreamweaver)