SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    textarea & javascript problem

    I have a form that take the values of a table.
    I have A textarea using tiny_mce.js.
    I want to use javascript to validate if elements are not empry.
    When the validation occurs and I deleted the content of text area, the validation see the text for the textarea when it had first loading.
    What is wrong?
    Dimis

  2. #2
    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)
    Show us your code.

    That sounds dirtier than it should.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
     <form onsubmit="return checkscript();" 
    action="cmp.php" method="post" name="myform" id="myform" enctype="multipart/form-data">
    Name:<br> <input type="text"  value="<? echo $myname ;?>"
    name="myname" id="myname"><br>
    Description:
    <!-- Gets replaced with TinyMCE, remember HTML in a textarea should be encoded -->
    <textarea id="descr" name="descr" rows="5" cols="30" ><?echo $mytext;?></textarea>  <br />
    Photo:<br> <input type="file" name="myphoto"> <?echo $myphoto?>
    <input type="hidden" value="<?echo  $myphoto ?>" name="prephoto">
    <input type="hidden" value="update" name="action">
    <input type="hidden" value="<?echo  $myid ?>" name="mycode">
     <br />
    <input type="submit" name="save" value="Submit" />
     <input type="reset" name="reset" value="Reset" />
    </form>
    HTML Code:
    function checkscript() {alert(document.myform.descr.value);
    	if (document.myform.myname.value=="" || document.myform.descr.value=="") {
    		// something is wrong
    		alert('Fill name and Description!');
    		return false;
    	}
    	// If the script makes it to here, everything is OK,
    	// so you can submit the form
    	return true;
    }

  4. #4
    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)
    It works for me on Firefox and Internet Explorer 7 and 8.
    When the description text is cleared, the submit button shows the empty description field contents, and the validation message.

    Am I to understand from you that you're still getting the description text after it's been cleared, and there is no validation message?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by pmw57 View Post
    It works for me on Firefox and Internet Explorer 8.
    When the description text is cleared, the submit button shows the empty description field contents, and the validation message.

    Am I to understand from you that you're still getting the description text after it's been cleared, and there is no validation message?
    I have the same code at the "new" form, there it works ok.
    At edit form when i clear the text area the form submits! I put a alert(textarea) when posting and it has the value of loading the page!I have xamp.


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
  •