Web Analytics Made Easy -
StatCounter help edit my syntax for event handler - CodingForum

Announcement

Collapse
No announcement yet.

help edit my syntax for event handler

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • help edit my syntax for event handler

    I have this event handler for the submit button. I want it to check to be sure there is no number entered in the field "ccnumber" on my form and then if that field is empty then post it to my .asp page --> my syntax stinks so could someone look over my code and let me know whats up?



    function btnSubmit_onclick() {

    if (form.ccnumber.value.length > 0) {
    alert("Please remove Credit Card Number.");
    form.ccnumber.focus();
    return;
    else

    document.thisForm.hidReload.value = "reload";
    document.thisForm.action = "AdminEditGroup-JP.asp";
    document.thisForm.submit("post");
    }

  • #2
    1. You should use event handler onsubmit placed in form not onclick placed in button.
    2. use return true/false boolean condition to continue/stop the submit process


    <script>
    function verify(){
    d = document form[0];
    if (d.ccnumber.value.length > 0) {
    alert("Please remove Credit Card Number.");
    d.ccnumber.focus();
    return false;
    }
    else{return true}
    }
    </script>
    ..
    ..

    <form onsubmit="return verify()">
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

    Comment


    • #3
      d = document forms[0];

      sorry for mistyping
      KOR
      Offshore programming
      -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

      Comment


      • #4
        that is correct now

        <script>
        function verify(){
        d = document.forms[0];
        if (d.ccnumber.value.length > 0) {
        alert("Please remove Credit Card Number.");
        d.ccnumber.focus();
        return false;
        }
        else{return true}
        }
        </script>
        KOR
        Offshore programming
        -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

        Comment


        • #5
          You can easily pass the form reference.
          Code:
          function verify(oForm){
            if (oForm.ccnumber.value.length > 0) {
               alert("Please remove Credit Card Number.");
               oForm.ccnumber.focus();
               return false;
             }
             ...
          }
          ...
          <form onsubmit="return verify([b]this[/b])">
          Glenn
          vBulletin Mods That Rock!

          Comment

          Working...
          X