ShaolinF Posted July 29, 2007 Share Posted July 29, 2007 Hi Guys, What I want to do is a have a text box on a page and if the user hasnt filled out this text box and presses continue the following text will be written "Please enter something into the text box". How can I do this ? Quote Link to comment Share on other sites More sharing options...
Devine Posted July 29, 2007 Share Posted July 29, 2007 <?php $textbox=$_POST['textbox']; if($textbox==""){ echo" <form action='?' method='post'> <textarea cols='20' rows='4' name='textbox'> $textbox </textarea> </form> "; }else{ echo"You listened to me "; } Quote Link to comment Share on other sites More sharing options...
corbin Posted July 29, 2007 Share Posted July 29, 2007 You could also do it with Javascript (I would do it with PHP too if you were going to do it with javascript): <script language="javascript"> <!-- function Submitted(form) { if(form.textbox.length < 1) { alert('Please enter something in the textarea.'); return false; } return true; //not sure if textbox.length is the right format.... I don't use javascript to validate forms very often //also, you could alter a div or just plain write something if it failed instead of alerts, which are like insanely annoying to me } //--> </script> <form action="" method="POST" onsubmit="return Submitted(this);"> <textarea name='textbox' id='textbox'> </textarea> </form> Quote Link to comment Share on other sites More sharing options...
ShaolinF Posted July 29, 2007 Author Share Posted July 29, 2007 Thanks for the imput guys but I don't know how to implmenet it within html. Here is my textbox: <p>Character string shown: <input type="text" name="validator" id="validator" size="20" /></p> And my submit button: <button type="submit" value="Continue">Continue</button> Quote Link to comment Share on other sites More sharing options...
marcus Posted July 29, 2007 Share Posted July 29, 2007 What corbin did you can just do: <form name="submit" method="post" action="page.php" onSubmit="Submitted(submit)"> <textarea name="textbox" cols="30" rows="14"></textarea> <br><input type="submit" value="Submit"> </form> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.