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
https://forums.phpfreaks.com/topic/70325-solved-form-submit/
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
https://forums.phpfreaks.com/topic/70325-solved-form-submit/#findComment-353470
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.