HighDots Forums  

JS question--what is wrong with my code?

Macromedia Dreamweaver Macromedia Dreamweaver Discussions (macromedia.dreamweaver)


Discuss JS question--what is wrong with my code? in the Macromedia Dreamweaver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
middletree
 
Posts: n/a

Default JS question--what is wrong with my code? - 07-15-2004 , 03:21 PM






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);
}



Reply With Quote
  #2  
Old   
Mick White
 
Posts: n/a

Default Re: JS question--what is wrong with my code? - 07-15-2004 , 04:46 PM







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:

Quote:
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);
}



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.