Results 1 to 3 of 3

Thread: JavaScript/Submit Button ?

  1. #1

    Thread Starter
    Lively Member Nator's Avatar
    Join Date
    Nov 1999
    Location
    East Larryville, GA
    Posts
    80

    JavaScript/Submit Button ?

    This is probably pretty easy, but I am newbie, so here goes.
    How do you check a condition with javascript before a form is submitted using a submit button?

    I need to make sure my users have picked an item from a dropdown box, before they go on to the next page. I've having my submit button call a function, but it seems to ignore it.

    <SCRIPT language=javascript>

    function fncCheckLetter()
    {
    if(window.formLetterData.cboLetterType.value=="")
    {
    // User did not select an item from the list.
    alert("You must pick a valid item.");
    }
    }
    </SCRIPT>

    <INPUT id=btnSubmitLetter name=btnSubmitLetter type=submit value=Submit tabIndex=1 onClick="fncCheckLetter">

    Is there a better way or do I have to do something extra with my script?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Code:
    <SCRIPT language=javascript> 
    
    function fncCheckLetter() 
    { 
    if(window.formLetterData.cboLetterType.value=="") 
    { 
    // User did not select an item from the list. 
    alert("You must pick a valid item."); 
    return false;
    }
    else
    {
      return true;
    }
    
    } 
    </SCRIPT> 
    
    <form onSubmit="return fncCheckLetter()">
    <INPUT id=btnSubmitLetter name=btnSubmitLetter type=submit value=Submit tabIndex=1 >
    </form>
    that should work

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Sadovod
    Guest
    You should use following statement in your JS:
    doc.form.selectList.options[ selecteditem ].text=="whatTheyPick"
    It will work in NS too.

Posting Permissions

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



Click Here to Expand Forum to Full Width