cha0sriderx Posted September 23, 2007 Share Posted September 23, 2007 well first off, i dont really know anything ab javascript. The part that i have coded so far was from just what i saw on tutorial sites. Okay well im trying to make a shoutbox for my site, but when they click submit i want it to check and see if the 'name' field and 'message' field isnt still the default value or nulled. or if it is easier, have submit disabled and when they edit either the 'name' or 'message' it checks both fields to make sure it isnt the default value or nulled. Javascript part. <script type='text/javascript'> function submitform(){ var gname=document.shoutbox.name.value; var gmessage=document.shoutbox.message.value; if( (gname.length == 0) || (gname.value == 'name') ){ alert('Please enter your name.'); } elseif( (gmessage.length == 0) || (gmessage.value == 'comment') ){ alert('Please enter your comment.'); } else { document.shoutbox.submit(); } } </script> form part. <form action="shout.php" target="shoutbox" name="shoutbox" method="post" style="margin:0px;"> <table class="shoutbox2"> <tr> <td align="center"> <input type="text" name="name" maxlength="25" value="name" size="25" /> </td> </tr> <tr> <td align="center"> <input type="text" name="message" maxlength="250" value="comment" size="25" /> </td> </tr> <tr> <td align="right"> <input type="submit" value="shout" onClick="javascript: submitform()" /> <input type="reset" value="reset" /> </td> </tr> </table> </form> Quote Link to comment Share on other sites More sharing options...
cha0sriderx Posted September 23, 2007 Author Share Posted September 23, 2007 nvm i got it to work. if anyone would like the view the correct code its listed below. <script type='text/javascript'> function checkform() { var gname=document.shoutbox.name.value; var gmessage=document.shoutbox.message.value; if ( (gname.length == 0) || (gname == 'name') ) { alert('Please enter your name.'); return false; } else if ( (gmessage.length == 0) || (gmessage == 'comment') ) { alert('Please enter your comment.'); return false; } return true; } </script> <form action="files/shoutbox/shout.php" onSubmit="return checkform()" method="POST" style="margin:0px;" name="shoutbox"> <table class="shoutbox2" cellpadding="1" cellspacing="0" align="center"> <tr> <td align="center"> <input type="text" name="name" maxlength="25" value="name" size="25" /> </td> </tr> <tr> <td align="center"> <input type="text" name="message" maxlength="250" value="comment" size="25" /> </td> </tr> <tr> <td align="right"> <input type="submit" value="shout" /> <input type="reset" value="reset" /> </td> </tr> </table> </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.