SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Form won't validate

    I have changed thisover and over, searched the forum, searched the web, but It just won't work - can anyone see a problem with it. It submits regardless - never any message.


    <script language='JavaScript'>

    function validate(myform)
    {
    valid = true;
    if (myform.rname.value == "")
    {
    alert('Please enter your name');
    valid = false;
    }

    return valid;
    }
    {
    if (document.myform.rphone.value == " ")
    {
    alert('Please enter your phone number');
    return false;
    }
    else
    return true;
    }

    </script>

    </head><center><BODY bgColor=ffffff leftmargin='1' topmargin='1' bottommargin='1'>
    <table border=0 width=100%><td class="logo">
    <img src='backbanner.gif' alt='Adkins Arboretum' width='519' height='114' border='0'></td></tr></table>
    <div align='center'> <h2 style='font: green bold italic small-caps 18px georgia, serif'>Plant Order</h2></div><br><br>



    <form name="myform" action="./index.php" method="POST" onsubmit="return validate(this);">
    <table width=560 bgcolor='#000000' cellspacing='1' cellpadding='3'><td class='menu'>
    <b>Please fill out the following form/b></td></tr></table>
    <table width=560 bgcolor='#000000' valign='top' cellspacing='1' cellpadding='3'>
    <td width=100 class=hd2>Name: </td><td width=200 class=hd3>
    <input type='text' name='rname' size=25 value="" onblur="validate(this)"></td>
    <td class=hd2 width=200>Address: </td><td class=hd3><textarea name='raddress'></textarea></td>
    </tr>

    <td class=hd2>Phone: </td><td class=hd3>
    <input type='text' name='rphone' value=''></td>

    <td class=hd2> Email: </td><td class=hd3>
    <input type='text' name='remail' value=''></td>

    </tr>
    <td class=hd2>Comments/td><td class=hd3>
    <textarea name='rbreif'></textarea></td>
    <td class=hd2>

    </td><td class=hd3>

    </td>
    </tr>

    </table>
    <input type='submit' value="Checkout" name="Checkout">

    </form>

    You may notice I tried it with both the document. in the string and without - makes no difference..Also tried the onblur thingy in there.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,026
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)

    curly braces

    This should be throwing an error. The curly braces don't match up correctly.
    Code:
    function validate(myform)
    {
    	valid = true;
    	if (myform.rname.value == "")
    	{
    		alert('Please enter your name');
    		valid = false;
    	}
    
    	return valid;
    }
    { /* is this for a missing else if ? */
    if (document.myform.rphone.value == " ")
    {
    	alert('Please enter your phone number');
    	return false;
    }
    else
    return true;
    } /* what is this closing ? */

  3. #3
    SitePoint Member
    Join Date
    Jan 2006
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks,
    Actually found that after spending hours. It's almost ALWAYS something stupid! Don't know why it didn't error, but I ended up calling an outside script to do the validation and it works like a charm. Found this one at http://www.dboorn.com/javascript_for...n.php?catID=69
    so easy, my dog could do it!


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
  •