Disable Submit Button until Accept Terms and Redirect Page on Submit

Discussion in 'Javascript' started by Paul Oakfleet, Sep 10, 2003.

  1. The script below will disable Submit button until user accept terms,
    and will redirect user to another page after clicking on Submit
    button.

    The script seems to work fine on my PC (Windows XP, IE6), however I
    don't know if it's written well. I would like the opinion of someone
    who knows how to write these codes properly. Please let me know if
    there're any logic errors.

    PS: Please keep in mind that I didn't write this script, I found it
    over the internet. Therefore do not make me responsible for (1)
    copyright, (2) any damage this script may cause, (3) incompatibility,
    (4) bugs this script may have.

    Here's my entire page:

    <html>
    <head>
    <script>


    var checkobj

    function agreesubmit(el){
    checkobj=el
    if (document.all||document.getElementById){
    for (i=0;i<checkobj.form.length;i++){ //hunt down submit button
    var tempobj=checkobj.form.elements
    if(tempobj.type.toLowerCase()=="submit")
    tempobj.disabled=!checkobj.checked
    }
    }
    }

    function defaultagree(el){
    if (!document.all&&!document.getElementById){
    if (window.checkobj&&checkobj.checked)
    return true
    else{
    alert("Please Read/Accept our Terms of Service/Agreement to
    continue.")
    return false
    }
    }
    }

    </script>
    <SCRIPT LANGUAGE="JavaScript">

    var destination="redirectingpage.htm";

    function redirect()
    {
    window.location = destination;
    }

    // End -->
    </script>
    </head>
    <body>
    <form method="post" name=agreeform onSubmit="return
    defaultagree(this)" action="javascript:redirect()">
    <iframe name="agreement" src="email/agreement.htm" border="0"
    frameborder="0" marginwidth="3" marginheight="3" width="600"
    height="110" style="border: 3px solid #294A63">
    Your browser does not support inline frames or is currently configured
    not to display inline frames.</iframe></p>
    <input name="agreecheck" value="agree" type="checkbox"
    onClick="agreesubmit(this)">I Agree to the above Terms of
    Service/Agreement<br>
    <input type="Submit" value="Continue" disabled></form>
    <script>
    document.forms.agreeform.agreecheck.checked=false
    </script>
    </body>
    </html>
    Paul Oakfleet, Sep 10, 2003
    #1
    1. Advertising

  2. In article <>,
    (Paul Oakfleet) wrote:
    > ...
    > The script seems to work fine on my PC (Windows XP, IE6), however I
    > don't know if it's written well. I would like the opinion of someone
    > who knows how to write these codes properly. Please let me know if
    > there're any logic errors.
    >
    > PS: Please keep in mind that I didn't write this script, I found it
    > over the internet.


    > Here's my entire page:
    >
    > <html>
    > <head>
    > <script>


    Should be <script language="javascript"> or for modern browsers
    <script type="text/javascript">

    >
    > var checkobj


    not needed

    >
    > function agreesubmit(el){
    > checkobj=el
    > if (document.all||document.getElementById){
    > for (i=0;i<checkobj.form.length;i++){ //hunt down submit button
    > var tempobj=checkobj.form.elements
    > if(tempobj.type.toLowerCase()=="submit")
    > tempobj.disabled=!checkobj.checked
    > }
    > }
    > }


    No search needed. Just give the Submit button a
    name, e.g., "submitter" (don't call it "submit"!).
    Then you can write

    function agreesubmit(checkobj) {
    checkobj.form.submitter.disabled = !checkobj.checked;
    }

    > function defaultagree(el){
    > if (!document.all&&!document.getElementById){
    > if (window.checkobj&&checkobj.checked)
    > return true
    > else{
    > alert("Please Read/Accept our Terms of Service/Agreement to
    > continue.")
    > return false
    > }
    > }
    > }


    I don't know what that outer IF is for, and window.checkobj
    looks bogus to me. Also el (for element?) is a poor name,
    given it's really the form. Better code would be

    function defaultagree(form) {
    if (!form.agreecheck.checked) {
    alert(Please Read/Accept our Terms of Service/Agreement to continue.");
    }
    return form.agreecheck.checked;
    }
    >
    > </script>
    > <SCRIPT LANGUAGE="JavaScript">


    drop these two lines. Why close the script element
    just to restart it?


    >
    > var destination="redirectingpage.htm";
    >
    > function redirect()
    > {
    > window.location = destination;
    > }
    >
    > // End -->
    > </script>
    > </head>
    > <body>
    > <form method="post" name=agreeform onSubmit="return
    > defaultagree(this)" action="javascript:redirect()">
    > <iframe name="agreement" src="email/agreement.htm" border="0"
    > frameborder="0" marginwidth="3" marginheight="3" width="600"
    > height="110" style="border: 3px solid #294A63">
    > Your browser does not support inline frames or is currently configured
    > not to display inline frames.</iframe></p>


    there's no <p> for this </p>

    > <input name="agreecheck" value="agree" type="checkbox"
    > onClick="agreesubmit(this)">I Agree to the above Terms of
    > Service/Agreement<br>
    > <input type="Submit" value="Continue" disabled></form>


    add name="submitter" to this <input>

    > <script>
    > document.forms.agreeform.agreecheck.checked=false
    > </script>
    > </body>
    > </html>
    Chris Riesbeck, Sep 10, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ghafran Abbas
    Replies:
    0
    Views:
    4,207
    Ghafran Abbas
    Oct 12, 2004
  2. Chris
    Replies:
    5
    Views:
    3,893
    liangdong
    Jul 31, 2011
  3. ChrisN
    Replies:
    3
    Views:
    488
    Steve C. Orr [MCSD, MVP, CSM, ASP Insider]
    Apr 4, 2007
  4. Nicola Branzoli
    Replies:
    0
    Views:
    213
    Nicola Branzoli
    May 3, 2011
  5. Chuck
    Replies:
    0
    Views:
    259
    Chuck
    Nov 10, 2003
Loading...

Share This Page