Method being called on wrong button in FireFox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TheSouthLondonSlasher

    Method being called on wrong button in FireFox

    Thank you in advance to anyone who may be able to help. This is my
    first attempt at JavaScript, so I apologize if I've done something
    blatantly stupid in the below code. Basically, I have a form with 4
    checkboxes, a submit button, and a cancel button. When the user
    clicks submit, the page should build the URL, and submit the form, as
    long as one or more boxes is checked. When the user clicks cancel,
    they should be redirected back to the main page. The problem is that
    this works in IE, but FireFox and Safari (Which I'm sure aren't as
    forgiving) seem to call BOTH methods when cancel is clicked. Please
    forgive the <%= %>'s. This is actually part of a JSP, and some values
    come from the java.

    Any help pointing out things I've done incorrectly will be greatly
    appreciated! I'd really like this to work, but I'd also like to
    learn, and do it correctly. Thanks again!

    <SCRIPT type="text/javascript">
    // Validate the form, build the URL, and submit it.
    function handleForm(){

    // If the user has not selected anything, display a message and don't
    continue.
    if (document.mainF orm.eAdmin.chec ked == false &&
    document.mainFo rm.eEditor.chec ked == false &&
    document.mainFo rm.iAdmin.check ed == false &&
    document.mainFo rm.iEditor.chec ked == false) {
    alert ('Please select at least one role before continuing.');

    } else {
    // Disable the button so we don't get bonus submits
    document.mainFo rm.submitForm.d isabled=true;
    // Build an array of chosen roles
    var op_requestedApp s = new Array();
    if (document.mainF orm.eAdmin.chec ked == true) {
    op_requestedApp s.push("TSEA");
    }
    if (document.mainF orm.eEditor.che cked == true) {
    op_requestedApp s.push("TSEE");
    }
    if (document.mainF orm.iAdmin.chec ked == true) {
    op_requestedApp s.push("TSIA");
    }
    if (document.mainF orm.iEditor.che cked == true) {
    op_requestedApp s.push("TSIE");
    }

    // Compose the URL and submit
    document.mainFo rm.action="user/activate.jsp?id =<%= id
    %>&op_enduserId =<%= id %>&op_requester Id=<%= req %>&op_requested Apps="
    + op_requestedApp s;
    document.mainFo rm.submit();
    }
    }

    // Redirect the user back to the main page.
    function cancelForm(){
    location.replac e("user/main.jsp");
    }
    </SCRIPT>

    <form name="mainForm" onsubmit="handl eForm();" action=""
    method="post">
    <input class="input" type="checkbox" title="Access" name="eAdmin"
    id="eAdmin" />
    <label for="eAdmin">Ex tranet Administrator</label><br />


    <input class="input" type="checkbox" title="Access" name="eEditor"
    id="eEditor" />
    <label for="eEditor">E xtranet Editor</label><br />

    <input class="input" type="checkbox" title="Access" name="iAdmin"
    id="iAdmin" />
    <label for="iAdmin">In tranet Administrator</label><br />

    <input class="input" type="checkbox" title="Access" name="iEditor"
    id="iEditor" />
    <label for="iEditor">I ntranet Editor</label>

    <br /><br />


    <button name="submitFor m" value="submitFo rm" type="submit">S ubmit</
    button>
    <button name="cancelFor m" value="cancelFo rm"
    onClick="cancel Form();">Cancel </button>
    </form>
  • Doug Gunnoe

    #2
    Re: Method being called on wrong button in FireFox

    On Aug 5, 2:08 pm, TheSouthLondonS lasher <bigdave.sm...@ gmail.com>
    wrote:
    >
                            <button name="submitFor m" value="submitFo rm" type="submit">S ubmit</
    button>
                            <button name="cancelFor m" value="cancelFo rm"
    onClick="cancel Form();">Cancel </button>
                    </form>
    Hello.

    The following is from here: http://www.w3schools.com/tags/tag_button.asp

    ------
    HTML <buttontag

    Definition and Usage

    Defines a push button. Inside a button element you can put content,
    like text or images. This is the difference between this element and
    buttons created with the input element.

    Important: Be careful when using the button element in a form. In a
    form the different browsers will submit different values. Internet
    Explorer will submit the text between the <buttonand </buttontags,
    while other browsers will send the content of the value attribute.
    When in a form, use the input element instead.

    Note: The type attribute should always be specified. The default
    button type for Internet Explorer is "button", while in other browsers
    (and the W3C specification) it is "submit".

    ------

    In particular, notice the last sentence above. ^

    Comment

    • TheSouthLondonSlasher

      #3
      Re: Method being called on wrong button in FireFox

      On Aug 5, 5:34 pm, Doug Gunnoe <douggun...@gma il.comwrote:
      On Aug 5, 2:08 pm, TheSouthLondonS lasher <bigdave.sm...@ gmail.com>
      wrote:
      >
      >
      >
                              <button name="submitFor m" value="submitFo rm" type="submit">S ubmit</
      button>
                              <button name="cancelFor m" value="cancelFo rm"
      onClick="cancel Form();">Cancel </button>
                      </form>
      >
      Hello.
      >
      The following is from here:http://www.w3schools.com/tags/tag_button.asp
      >
      ------
      HTML <buttontag
      >
      Definition and Usage
      >
      Defines a push button. Inside a button element you can put content,
      like text or images. This is the difference between this element and
      buttons created with the input element.
      >
      Important: Be careful when using the button element in a form. In a
      form the different browsers will submit different values. Internet
      Explorer will submit the text between the <buttonand </buttontags,
      while other browsers will send the content of the value attribute.
      When in a form, use the input element instead.
      >
      Note: The type attribute should always be specified. The default
      button type for Internet Explorer is "button", while in other browsers
      (and the W3C specification) it is "submit".
      >
      ------
      >
      In particular, notice the last sentence above. ^
      Doug,

      Thank you so much for your help. Going back and looking at some
      examples, I now see the error of my ways. I was afraid it was
      something so simple :)

      If there are any other anomalies in the code I presented, please let
      me know, and thanks again!

      Comment

      Working...