Reply
can't get js to work with guest book
Old 10-25-2006, 01:46 PM can't get js to work with guest book
jason_bristol's Avatar
Ultra Talker

Posts: 267
Name: Jason Eyermann
Location: england bristol
I some added js to my guest book page. If someone pushes the submit button but does not leave a name I want to inform the viewer that they need to insert a name. I've done that fine but the only problem is that when I then push OK on the pop the page still continues to progress and enteres the viewers entry in.

How can I stop the loading the message being put thourgh.

here is the java script and the formdetails.

thanks for any help

Code:
<script type="text/javascript">
	  
	  function formValidator(){
	var firstname = document.getElementById('moreInfo');
	if(emptyBox(firstname, "Please enter your name.")){
							return true;
						} else {
		return false;
	
}
}
	  function emptyBox(elementJason, returnMessage) {
	       if (elementJason.value.length == 0) {
		         alert(returnMessage);
				 elementJason.focus();
				 return true;
			} else {
			  return false;
		}
		}
		</script>
HTML Code:
<form method="post" name="form1" onsubmit="return formValidator()" action="<?php echo $editFormAction; ?>">
        <table align="center">
          <tr valign="baseline">
            <td width="82" align="right" nowrap class="headerwhite">Name:</td>
            <td width="419"><input type="text" id="moreInfo" name="Name" value="" size="32"></td>
          </tr>
          <tr valign="baseline">
            <td align="right" nowrap class="headerwhite">Location:</td>
            <td><input type="text" name="Location" value="" size="32"></td>
          </tr>
          <tr valign="baseline">
            <td align="right" nowrap class="headerwhite">Email:</td>
            <td><input type="text" name="Email" value="" size="32"></td>
          </tr>
          <tr valign="baseline">
            <td align="right" nowrap class="headerwhite">Website:</td>
            <td><input type="text" name="Website" value="" size="32"></td>
          </tr>
          <tr valign="baseline">
            <td align="right" valign="top" nowrap class="headerwhite">Comments:</td>
            <td><textarea name="Comments" cols="50" rows="5"></textarea>
            </td>
          </tr>
          <tr valign="baseline">
            <td nowrap align="right">&nbsp;</td>
           <td><input type="image" value="Insert record" name="submit" src="../images/submitbutton.jpg"></td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="form1">
      </form>
jason_bristol is offline
Reply With Quote
View Public Profile Visit jason_bristol's homepage!
 
When You Register, These Ads Go Away!
Old 10-25-2006, 08:08 PM Re: can't get js to work with guest book
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
Converting Video For YouTube
Posts: 2,339
Name: Keith Marshall
Location: West Hartford, CT
You just needed to reverse the true and false order in your function.

Code:
function formValidator(){
  var firstname = document.getElementById('moreInfo');
 if(emptyBox(firstname, "Please enter your name.")){
  return false;
 } else {
  return true; 
  }
}
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 10-26-2006, 11:04 AM Re: can't get js to work with guest book
jason_bristol's Avatar
Ultra Talker

Posts: 267
Name: Jason Eyermann
Location: england bristol
Big thanks mgraphic! It works now.

I'm now going to try and help 3 people on this site with something if I can. I think that should be a moral rule.

I tried to add talkupation but can't because i've already done it before.
jason_bristol is offline
Reply With Quote
View Public Profile Visit jason_bristol's homepage!
 
Reply     « Reply to can't get js to work with guest book
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Webmaster Resources Marketplace:
Software Development Company | Webhosting.UK.com | Text Link Brokers 


   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12584 seconds with 12 queries