Results 1 to 5 of 5

Thread: form problem

  1. #1
    Join Date
    Apr 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default form problem

    Here is check.htm:

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>

    <form action="check.js" method="get" name="check">
    <p>
    <input name="keword" type="text" id="keword" size="30" maxlength="40">
    <input type="submit" value="Check Username Availability">
    </p>
    </form>

    </body>
    </html>



    The form action calls the check.js script. Here it is:

    <SCRIPT language="JavaScript">
    {

    if(document.forms["check"].keyword.value.toLowerCase() == "kimberly"){
    {document.write("<b>Taken</b>")}

    if(document.forms["check"].keyword.value.toLowerCase() == "jennifer"){
    {document.write("<b>Taken</b>")}

    else {document.write("<b>Available</b>")}


    }
    </SCRIPT>

    When I submit this form, the actual check.js page appears. Can someone tell me what is wrong.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You can't have a javascript as a form action. What you can do though is use the form "onSubmit" attribute to pass the information to another page (or accomplish your function).

    So, your page would look like this:

    Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    <SCRIPT language="JavaScript">
    function check() {
    
    if(document.forms["check"].keyword.value.toLowerCase() == "kimberly"){
    {document.write("<b>Taken</b>")}
    
    if(document.forms["check"].keyword.value.toLowerCase() == "jennifer"){
    {document.write("<b>Taken</b>")}
    
    else {document.write("<b>Available</b>")}
    
    }
    
    }
    </SCRIPT>
    
    <form action="" method="get" name="check" onsubmit="check(); return false;">
    <p>
    <input name="keword" type="text" id="keword" size="30" maxlength="40">
    <input type="submit" value="Check Username Availability">
    </p>
    </form>
    
    </body>
    </html>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Apr 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    it helps...

    but it still doesn't work.

    When I enter 'kimberly' or 'jennifer' into the text field...nothing happens when I press the button.

    I want it to say "Taken"

    Do you see any other problems with this script?

    Thanks for your help.

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Try the below mentioned code

    Code:
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    
    <body>
    
    <SCRIPT language="JavaScript">
    function checkFields() 
    {
    var fieldValue = document.getElementById('keword').value;
    fieldValue = fieldValue.toLowerCase();
    
    if(fieldValue == "kimberly" || fieldValue == "jennifer")
    {document.write("<b>Taken</b>");}
    else 
    {document.write("<b>Available</b>");}
    return false;
    }
    </SCRIPT>
    <form action="" method="get" name="check" onsubmit="return checkFields();">
    <p>
    <input name="keword" type="text" id="keword" size="30" maxlength="40">
    <input type="submit" value="Check Username Availability">
    </p>
    </form>
    
    </body>
    </html>

  5. #5
    Join Date
    Apr 2007
    Posts
    40
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default thx

    Thank you both...it finally works!!!

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
  •