Jump to content

[SOLVED] form submit


cha0sriderx

Recommended Posts

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.