SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot charles_i's Avatar
    Join Date
    Apr 2007
    Location
    Toronto, Canada
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Form Validation for TEXTAREA not working

    Hello,

    I want a validation alert to notify when a TEXTAREA has not been filled out (ie nothing in it).

    I have searched the javascript sites and according to all the code I have seen this should work:

    Code:
    <script type="text/javascript">
    function checkFields(){
    	if (document.myform.reason.value =='') {
    		alert("working now");
    		return false;
    }
    </script>
          				
    <form name="myform" onsubmit="return checkFields()">
    	<textarea name="reason"></textarea>
    	<input type="submit">				
    </form>
    ... but it doesn't. All it does is put ?reason= in the URL. Any idea why?

    Thanks.

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're missing a closing brace:
    Code:
    <script type="text/javascript">
    function checkFields(){
    	if (document.myform.reason.value == '') {
    		alert("working now");
    		return false;
    	} // this one
    }
    </script>

  3. #3
    SitePoint Guru
    Join Date
    Sep 2006
    Posts
    731
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by charles_i View Post
    Code:
    <script type="text/javascript">
    function checkFields(){
    	if (document.myform.reason.value =='') {
    		alert("working now");
    		return false;
    }
    </script>
          				
    <form name="myform" onsubmit="return checkFields()">
    	<textarea name="reason"></textarea>
    	<input type="submit">				
    </form>
    All it does is put ?reason= in the URL.
    I expect that it's also putting something in the JavaScript console, like "missing '}' ".
    Tab-indentation is a crime against humanity.

  4. #4
    SitePoint Zealot charles_i's Avatar
    Join Date
    Apr 2007
    Location
    Toronto, Canada
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OOF! Stupid me. Thanks guys! I'm used to getting a serious error code if a brace is missing!


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
  •