Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    74
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Form Validation & Form Action

    Hi
    I am very, very new to Javascript and I am stuck.

    I am trying to create a form that validates user input & then displays a price without leaving the page.

    I have worked out all the validation part how do I make the form action display the result on the same page and not direct to a new page.

    My form looks like this currently.

    <form name="quick_price" id="quick_price" class="form" method="post">
    <label for="length">Length(mm's)</label>
    <input name="length" type="text" id="length" size="8" maxlength="5" />
    <label for="width">Width(mm's)</label>
    <input name="width" type="text" id="width" size="8" maxlength="5" />

    <input type="submit" value="Check Price" onclick="return validate(this)" class="submit"/> </form>


    and the validate javascript looks like this:

    function validate(form) {
    var length = quick_price.length.value;
    var width = quick_price.width.value;


    if(length == "") {
    inlineMsg('length','You must enter a measurement.',3);
    return false;
    }
    if(width == "") {
    inlineMsg('width','You must enter a measurement.',3);
    return false;
    }
    if(width < 100) {
    inlineMsg('width','Enter a measurement over 100mm.',3);
    return false;
    }

    if(width > 915) {
    inlineMsg('width','Enter a measurement under 915mm.',3);
    return false;
    }

    if(length < 100) {
    inlineMsg('length','Enter a measurement over 100mm.',3);
    return false;
    }

    if(length > 1220) {
    inlineMsg('length','Enter a measurement under 1220mm.',3);
    return false;
    }

    if (isNaN(length))
    {inlineMsg('length','Numerics Only Please .',3);
    return false;
    }

    if (isNaN(width))
    {inlineMsg('width','Numerics Only Please.',3);
    return false;
    }



    return true;
    }


    I can add a action="success.html" to the form tag which works fine but I want the action to be another javascript function, i.e. action="display_price ( )"

    I can then create the display_price function to write the result in a specificed area on the same page.

    A pointer in the right directions would be appreciated.

    THanks
    Rob

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,853
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    If you are simply looking for a javascript method(no server side processing required), then change type="submit" to type="button" and then call the display_price( ) function at the end of validate()
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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