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

Thread: form

  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy form

    Could anybody check what is wrong with my code, it does not give me anything... shouldn't it at least if I don't write anything in the form to give me the alert....
    how would I display the information given by the user in the form, in another page.
    <HTML>
    <HEAD>
    <TITLE>FRAMES</TITLE>
    <script Language="JavaScript">
    <!--
    function formSubmit()
    {
    document.forms.myForm.submit()
    }

    function validate()
    {

    x=document.myForm
    search=x.search.value
    minimum=x.minimum.value
    maximum=x.maximum.value

    if (search.length=0)
    {
    {
    alert("you must supply a product name")
    return false
    }
    else
    {
    return true
    }
    }

    }//end of function validate


    //-->
    </script>
    </HEAD>

    <BODY BGCOLOR="lightblue">


    <form name="myForm" onsubmit="return validate()">
    Search Product: <input type="text" name="search" size="20"><br />
    Minimum Price: <input type="text" name="minimum" size="20"><br />
    Maximum Price: <input type="text" name="maximum" size="20"><br />
    <br /><input type="button" onclick="formSubmit()" value="Submit"><INPUT TYPE="RESET">

    </form>

    </BODY>

    </HTML>

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Edinburgh, UK
    Posts
    402
    Thanks
    2
    Thanked 1 Time in 1 Post
    You're assigning 0 to search.length, not testing to see if it's equal to 0.

    Code:
    function validate()
    {
    
    x=document.myForm
    search=x.search.value
    minimum=x.minimum.value
    maximum=x.maximum.value
    
    if (search.length==0)
    {
    {
    alert("you must supply a product name")
    return false
    }
    else
    {
    return true
    }
    }
    Rich

    "An expert is a person who has made all the mistakes that can be made in a very narrow field."


  •  

    Posting Permissions

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