SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2004
    Location
    Boston
    Posts
    482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    need another set of eyes.

    Hi, This is driving me crazy. I have a small form I am trying to validate and it will not validate the <textarea> field for some reason. All the <input> fields work fine.

    What am I missing?

    Here is my code for the text area:

    HTML Code:
    <script>
    if (form.message.value == "" || form.message.value == "message*") {
    alert("Please enter a message.");
    form.message.focus();
    return false ;
    }
    </script>
    
    <textarea id="message" name="message">message*</textarea>
    Thank you.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,198
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Try using the following instead

    Code JavaScript:
    if (form.message.innerHTML == "" || form.message.innerHTML == "message*") {

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Rmazin View Post
    What am I missing?
    Your code seems to work perfectly well when it's used within an appropriate context:

    Code html4strict:
    <form id="myform">
    	<textarea id="message" name="message">message*</textarea>
    	<input type="submit">
    </form>
    <script>
    document.getElementById('myform').onsubmit = function () {
    	var form = this;
    	if (form.message.value == "" || form.message.value == "message*") {
    		alert("Please enter a message.");
    		form.message.focus();
    		return false;
    	}
    }
    </script>

    Can you show us more of how you're using your code? Perhaps, by providing us with a link to a test page?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •