Results 1 to 4 of 4

Thread: Need hepl COMBINING 2 JavaScripts... plz help!

  1. #1
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need hepl COMBINING 2 JavaScripts... plz help!

    Hi guys!

    One quick question... how to i go about useing the fallowing 2 scripts in my page:

    1. FORM FIELD VALIDATION

    <SCRIPT>
    function CheckForm( theform )
    {
    var bMissingFields = false;
    var strFields = "";

    if( theform.b_first.value.length < 3 ){
    bMissingFields = true;
    strFields += " * Billing Information: First Name\n";
    }
    if( theform.b_last.value.length < 3 ){
    bMissingFields = true;
    strFields += " * Billing Information: Last Name\n";
    }
    if( theform.b_addr.value.length < 5 ){
    bMissingFields = true;
    strFields += " * Billing Information: Address\n";
    }
    if( theform.b_city.value == '' ){
    bMissingFields = true;
    strFields += " * Billing Information: City\n";
    }
    if( theform.b_state.value.length != 2 ){ // State should be a 2 letter code
    bMissingFields = true; // If you want to use full state names then pls change != 2 into <5
    strFields += " * Billing Information: State\n";
    }
    if( theform.b_zip.value.length != 5 ){ // validate postalcode - invalid if entry is <> 6
    bMissingFields = true;
    strFields += " * Billing Information: Zip Code\n";
    }
    if( theform.b_phone.value.length < 3 ){
    bMissingFields = true;
    strFields += " * Billing Information: Phone number\n";
    }
    if( theform.b_email.value.search("@") == -1 || theform.b_email.value.search("[.*]") == -1 ){ // validate email
    bMissingFields = true;
    strFields += " * Billing Information: E-mail address\n";
    }

    if( bMissingFields ) {
    alert( "I'm sorry, but you must provide the following field(s) before continuing:\n\n" + strFields +"\nPlease complete the missing or invalid fields in the order form\nand click the Submit button to process the order." );
    return false;
    }

    // The SetCookie will empty the cart after the form has been send to your checkout processing scipt (PHP/PL).
    // If a user returns to the shop AFTER checkout, the cart will have no items in it.

    return true;
    }
    </SCRIPT>



    and...

    2. SUBMIT ONCE...

    <SCRIPT>
    function OnlyOnce( theform )
    {

    if (document.all || document.getElementById) {
    for (i = 0; i < theform.length; i++) {
    var tempobj = theform.elements[i];
    if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset")
    tempobj.disabled = true;
    }
    return true;
    }
    else {
    return true;
    }

    }
    </SCRIPT>



    The real question is... WHAT WILL MY EVENT HANDLER LOOK LIKE ex.: <form action="checkoutmail.php" method="POST" onSubmit="return OnlyOnce(this);" ?????????>

    Your help is higly apreciated.
    Thanks!

  2. #2
    Join Date
    Apr 2006
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation :(

    come on guys... isn't there any JAVASCRIPT GURU or... LITTLE GURU on this Forum.

    Is my PROBLEM so f$@#% hard!?

    Thanks!

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'd first like to point out that this forum is not real-time, and responses need not necessarily be prompt; I for one hadn't seen your post until now.


    Your best bet would be to drop the latter code altogether. If you want to prevent multiple submissions, then the best place to do that is server-side. If you consider such prevention important, then you must do it server-side. Relying on the client is a bad idea.

    There is another reason, though, for omitting the second function: if an error occurs whilst submitting the form, the user will be unable to use the back button and resubmit. Whilst the form controls should retain their previous value, the submit button may also remain in a disabled state.


    By the way, script elements have a required type attribute:

    HTML Code:
    <script type="text/javascript">
    Mike
    Last edited by mwinter; 04-11-2006 at 03:33 AM.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I don't really do JS, so I can't answer your question too well.

    However:
    1. The reason people probly aren't responding is, as is said in quite a few places, posting questions about 2 js's on one page isn't a great idea because it takes so long to figure out the interaction that many people just won't try.
    2. the reason is *usually* that two variables share the same name, causing problems. Aside from that, you just gotta put them in the right spots.

    also, for anyone to help, especially with a complex problem, please LINK to your page with issues.

    hope this ends up helping...


    EDIT: I see Mike responded... good... you can probly ignore this post then.

Bookmarks

Posting Permissions

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