help - my code is not stopping!

Results 1 to 4 of 4

Thread: help - my code is not stopping!

  1. #1
    schild01 Guest

    Default help - my code is not stopping!

    Hi,<BR><BR>I am running through some error checking jscript code and when it finds an error it doesn&#039t stop, but just keeps running and submits my form. How can I stop this. I have the same code on another page and I do not have this problem (beats me). <BR><BR>Thanks for any help - here&#039s the code:<BR><BR> function doSearch() {<BR> var fOk = true<BR> var strMsg<BR> <BR> if (document.frm_Add.status_type.selectedIndex &#060;= 0)<BR> {<BR> fOk = false<BR> alert("Status Type must not be blank");<BR> document.frm_Add.status_type.focus();<BR> } <BR> <BR> <BR> // if no errors, then submit the form<BR> if (fOk)<BR> document.frm_Add.submit();<BR> else<BR> alert(strMsg);<BR> } <BR> <BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: code is not stopping!

    I think your mistake is with your html-code.<BR>please give me:<BR>- what you write in the form-tag<BR>- how you submit<BR>(if button, give it&#039s tag, ...)<BR><BR><BR>Bart

  3. #3
    Steve W Guest

    Default RE: help - my code is not stopping!

    Sounds familiar...<BR><BR>It&#039s all down to one magic word; RETURN!<BR><BR>So, if you want your code to dump out after the first if statement tests FALSE:<BR><BR>function doSearch() {<BR>var fOk = true<BR>var strMsg<BR><BR>if (document.frm_Add.status_type.selectedIndex &#060;= 0)<BR>{<BR>fOk = false<BR>alert("Status Type must not be blank");<BR>document.frm_Add.status_type.focus();< BR>return;<BR>} <BR><BR><BR>// if no errors, then submit the form<BR>if (fOk)<BR>document.frm_Add.submit();<BR>else<BR>ale rt(strMsg);<BR>} <BR><BR>You can use return to send a value back to the calling function, by using:<BR><BR>return false;<BR>return true;<BR>return elephant; (variable name / object reference)<BR>return "elephant"; (string)<BR><BR>you get the idea...<BR><BR>WARNING! If you are executing the function from a link i.e.<BR><BR>&#060;a href="javascript:functionName()"&#062;Link&#060;/a&#062;<BR><BR>it should be written as follows:<BR><BR>&#060;a href="javascript:void(functionName())"&#062;Link&# 060;/a&#062;<BR><BR>This prevents the browser from rewriting the page with just the returned value, or, if you haven&#039t returned a value, just an hourglass (in the case of IE)<BR><BR>Good luck!<BR><BR><BR>

  4. #4
    schild01 Guest

    Default RE: help - my code is not stopping!

    thanks guys for your help.<BR><BR>It ended up being my HTML code which I finally found after a while, I was submitting my form twice and didn&#039t even realize.<BR><BR>Also thanks for the "return" bit - this will be helpful for me in some other things...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts