www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 28

Thread: Jscript object expected error at onsubmit="return validate(this);"> - Please Help!

  1. #1
    Join Date
    Mar 2011
    Posts
    19

    Exclamation Jscript object expected error at onsubmit="return validate(this);"> - Please Help!

    Hi,

    Gurus, need help! I'm trying to use a form which is existent on one of my sites and try re-creating a similar form on another site for the exact same purpose. Here is the URL for the form on our website Cast Iron Cookware Depot.

    I have everything duplicated but running into form validation errors. Right now without event entering any data into the form and also the verification code the form still gets submitted but ofcourse runs into "object expected" error at [ICODE]onsubmit="return validate(this);">[/ICODE] by IE Debugger. I'm not a coder and just trying to replicate what I already have on one site onto another. The same code is working fine on one site (with minor changes like the URL to the php file) but not on another. Need to know why.

    Below is the total code and would appreciate if any of you gurus point out where the mistake is and also why the exact same code is working on one site is not working on this site. Thanks much in advance. Please help me!
    ------------------------------------------------------------------------

    Code:
     
    <style>
    .TableBG
    {
    	background-color: #83a338;
    	color: #ffffff;
    	font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
    	font-size: 12px;
    	font-weight: bold;
    }
    .no
    {
    	font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
    	font-size: 12px;
    	font-weight: bold;
    	color: #333333;
    	width: 35px;
    	text-align:right;
    }
    input, textarea {border: 1px inset #cccccc; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 12px;}
    
    .input01 {width: 150px;}
    .input02 {width: 250px;}
    
    .button
    {
    	background-color: #83a338;
    	color: #000000;
    	border: 1px outset #83a338;
    	font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size: 12px;
    }
    
    </style><br />
    <br />
    <table width="600" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF" class="TableBG">
    
      <tr>
          <td bgcolor="#FFFFFF"> 
    	  <FORM name="form1" method="POST" action="http://s.p8.hostingprod.com/@castironcookwaredepot.com/php/tellafriend.php" onsubmit="return validate(this);">
              
    <table width="100%" border="0" cellpadding="5" cellspacing="0">
              <tr>
              	<td class="TableBG">&nbsp;</td>
              	<td class="TableBG"><strong>Your Name: </strong></td>
              	<td class="TableBG"><strong>Your Email: </strong></td>
              	</tr>
              <tr>
              	<td colspan="3" height="5"></td>
              	</tr>
              <tr>
              	<td>&nbsp;</td>
              	<td>
              		<input type="text" name="sName" class="input01" style="font-weight: bold;" />          	</td>
              	<td>
              		<input type="text" name="sEmail" class="input02" size="40" style="font-weight: bold;" />          	</td>
              	</tr>
              <tr>
    				<td colspan="3" height="5"></td>
              	</tr>
              <tr>
              	<td width="4%" class="TableBG">&nbsp;</td> 
                <td width="36%" class="TableBG"> Your Friend's Name :</td>
                <td width="60%" class="TableBG">Your Friend's Email:</td>
              </tr>
              <tr>
    				<td colspan="3" height="5"></td>
              	</tr>
              <tr>
              	<td class="no"><strong>1.</strong></td>
              	<td>
              		<input type="text" name="name1" class="input01" />          	</td>
              	<td>
              		<input type="text" name="email1" class="input02" size="40" />          	</td>
              	</tr>
              <tr>
              	<td class="no"><strong>2.</strong></td>
    				<td>
    					<input type="text" name="name2" class="input01" />				</td>
              	<td>
    					<input type="text" name="email2" class="input02" size="40" />				</td>
              	</tr>
              <tr>
              	<td class="no"><strong>3.</strong></td>
    				<td>
    					<input type="text" name="name3" class="input01" />				</td>
              	<td>
    					<input type="text" name="email3" class="input02" size="40" />				</td>
              	</tr>
              <tr>
              	<td class="no"><strong>4.</strong></td>
    				<td>
    					<input type="text" name="name4" class="input01" />				</td>
              	<td>
    					<input type="text" name="email4" class="input02" size="40" />				</td>
              	</tr>
              <tr>
              	<td class="no"><strong>5.</strong></td>
    				<td>
    					<input type="text" name="name5" class="input01" />				</td>
              	<td>
    					<input type="text" name="email5" class="input02" size="40" />				</td>
              	</tr>
              <tr>
    				<td class="TableBG">&nbsp;</td>
              	<td colspan="2" class="TableBG">Your Message </td>
              	</tr>
              <tr>
    				<td colspan="3" height="5"></td>
              	</tr>
              <tr>
    				<td colspan="3" align="center">
              			<textarea name="comments" cols="65" rows="5" id="comments" style="width: 420px;"></textarea>          	</td>
              	</tr>
    			<tr>
    				<td class="TableBG">&nbsp;</td>
              	<td colspan="3" class="TableBG">Enter Verification Code</td>
              	</tr>
              <tr>
    				<td colspan="3" height="5"></td>
              	</tr>
    
    			<tr>
    <td colspan="3" align="center" valign="absmiddle"><img src="http://s.p8.hostingprod.com/@castironcookwaredepot.com/php/captcha.php" align="absmiddle">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="text" name="vercode" value="Enter Verification Code" onFocus="if(this.value=='Enter Verification Code') this.value='';" onBlur="if(this.value=='') this.value='Enter Verification Code';" size="25"/></td>
    </tr>
              
              <tr>
              	<td colspan="3" align="center">
              		<input type="submit" name="Submit" value=" Send Email " class="button" />          	</td>
              	</tr>
            </table>
    	    </form>
          </td>
      </tr>
    </table>
    <script>
    function validate(frm)
    {
    	name = frm.sName;
    	email = frm.sEmail;
    	name1=frm.name1;
    	email1=frm.email1;
    
    	err_flag = 0;
    	
    	if (name.value == "" || !removeSpaces(name.value))
    		{
    			alert ("Please enter proper Name!");
    			name.value="";
    			name.focus();
    			return false;	
    		}
    		else if (email.value == "" || !validate_email(email.value))
    			{
    			alert ("Please enter proper Email!");
    			email.value="";
    			email.focus();
    			return false;	
    		}
    	
    		else if (name1.value == "" || !removeSpaces(name1.value))
    			{
    				alert ("Please enter proper Friend\'s Name!");
    				name1.value="";
    				name1.focus();
    				return false;	
    			}
    			else if (email1.value == "" || !validate_email(email1.value))
    				{
    					alert ("Please enter proper Friend\'s Email!");
    					email1.value="";
    					email1.focus();
    					return false;	
    				}
    
    }
    
    function validate_email(e)
    {
    	var str=e;
    	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    
    	if (!filter.test(str))
    		return false;
    	else
    		return true;
    }
    
    function removeSpaces(string) {
    	var tstring = "";
    	string = '' + string;
    	splitstring = string.split(" ");
    	for(i = 0; i < splitstring.length; i++)
    	tstring += splitstring[i];
    	return tstring;
    }
    </script>
    <br />
    <br />
    Regards
    Learner

  2. #2
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Is the function after the form? Or is it inside the HEAD tag?

    ^_^

  3. #3
    Join Date
    Mar 2011
    Posts
    19

    Exclamation

    Thanks for your response. I do not know the answer to your question. But I'm just trying to recreate the page existing and working at BSA Tell a Friend on my other site CCID Tell a Friend. You can hit the "Send Button" without filling a word in the form andit still gets submitted. Need to know the fix.

    I'm unable to figure out the difference between the two pages.

    Regards
    Learner

  4. #4
    Join Date
    Mar 2011
    Posts
    19
    Anyone? Thx.

  5. #5
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    You are working on this page, but you can't tell me if the <script> tags containing the function are above or below the form. Something doesn't sound right.

    At a glance, I can't see anything wrong. If you click on the SUBMIT button and IMMEDIATELY hit the escape key, you'll prevent the form from being submitted and (hopefully) should be able to report any JavaScript error messages that happen. (That is, if you are using Internet Explorer.) If you are using FireFox, open the error console after you submit the form and find any entries marked as ERROR.

    ^_^

  6. #6
    Join Date
    Mar 2011
    Posts
    19
    Now I get what you were asking. When yu asked about a function I was confused, pardon my ignorance for not being a programmer. The <script> tags are withing the <body> tags and not within the <head> tags.

    I did try submitting and hitting esc and IE debugger said "object expected" tellafriend, line 56, character 1

    The line 56 is below:

    Code:
    <FORM name="form1" method="POST" action="http://s.p8.hostingprod.com/@castironcookwaredepot.com/php/tellafriend.php" onsubmit="return validate(this);">
    I have attached the pic too. Please let me know what I need to do to make the form validate the entries in the field are right before submitting teh form.

    Thanks
    Learner
    Attached Images Attached Images

  7. #7
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    I can't say, for sure, but I can guess.

    Most likely, the form isn't finding the validate function (I suspect that is the object it's looking for.) Move the function so that it's inside the <head> tag.

    I'm also going to guess (coz I can't be absolutely sure) that it may not like what you have entered in the action parameter. To my knowledge, "@" does not belong in an HTTP/HTTPS protocol (it's useful in FTP, for logging in, but not HTTP/HTTPS). Is there any way you can aim it at a proper FQDN (Fully-Qualified Domain Name) like
    "http://www.castironcookwaredepot.com/php/tellafriend.php" ?

    If any other JavaScript veteran knows about this last point, please chime in; I've never seen an action parameter like that, before, and could use some insight, myself.

    ^_^

  8. #8
    Join Date
    Mar 2011
    Posts
    19
    Thanks. I would try moving it to the <head> tag and see. Let me give you a quick background of our website. Our websites are hosted on Yahoo and also called Yahoo stores and they use RTML language which ultimately convert all RTML parameters to HTML.

    I have no idea about the @ symbol but the same symbol and same statement is working fine on my other website. Below is the code use on the other website which I'm trying to replicate here with minor changes.

    Code:
    <style>
    .TableBG
    {
    	background-color: #878573;
    	color: #ffffff;
    	font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
    	font-size: 11px;
    	font-weight: bold;
    }
    .no
    {
    	font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif;
    	font-size: 11px;
    	font-weight: bold;
    	color: #333333;
    	width: 35px;
    	text-align:right;
    }
    input, textarea {border: 1px inset #cccccc; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 11px;}
    
    .input01 {width: 150px;}
    .input02 {width: 250px;}
    
    .button
    {
    	background-color: #efefef;
    	color: #000000;
    	border: 1px outset #dddddd;
    	font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif; font-size: 11px;
    }
    
    </style><br />
    <br />
    <table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF" class="TableBG">
    
      <tr>
          <td bgcolor="#FFFFFF"> 
    	  <FORM name="form1" method="POST" action="http://s.p4.hostingprod.com/@bestsafetyapparel.com/php/tellafriend.php" onsubmit="return validate(this);">
          	<table width="100&#37;" border="0" cellpadding="5" cellspacing="0">
              <tr>
              	<td class="TableBG">&nbsp;</td>
              	<td class="TableBG"><strong>Your Name: </strong></td>
              	<td class="TableBG"><strong>Your Email: </strong></td>
              	</tr>
              <tr>
              	<td colspan="3" height="5"></td>
              	</tr>
              <tr>
              	<td>&nbsp;</td>
              	<td>
              		<input type="text" name="sName" class="input01" style="font-weight: bold;" />          	</td>
              	<td>
              		<input type="text" name="sEmail" class="input02" size="40" style="font-weight: bold;" />          	</td>
              	</tr>
              <tr>
    				<td colspan="3" height="5"></td>
              	</tr>
              <tr>
              	<td width="4%" class="TableBG">&nbsp;</td> 
                <td width="36%" class="TableBG"> Your Friend's Name :</td>
                <td width="60%" class="TableBG">Your Friend's Email:</td>
              </tr>
              <tr>
    				<td colspan="3" height="5"></td>
              	</tr>
              <tr>
              	<td class="no"><strong>1.</strong></td>
              	<td>
              		<input type="text" name="name1" class="input01" />          	</td>
              	<td>
              		<input type="text" name="email1" class="input02" size="40" />          	</td>
              	</tr>
              <tr>
              	<td class="no"><strong>2.</strong></td>
    				<td>
    					<input type="text" name="name2" class="input01" />				</td>
              	<td>
    					<input type="text" name="email2" class="input02" size="40" />				</td>
              	</tr>
              <tr>
              	<td class="no"><strong>3.</strong></td>
    				<td>
    					<input type="text" name="name3" class="input01" />				</td>
              	<td>
    					<input type="text" name="email3" class="input02" size="40" />				</td>
              	</tr>
              <tr>
              	<td class="no"><strong>4.</strong></td>
    				<td>
    					<input type="text" name="name4" class="input01" />				</td>
              	<td>
    					<input type="text" name="email4" class="input02" size="40" />				</td>
              	</tr>
              <tr>
              	<td class="no"><strong>5.</strong></td>
    				<td>
    					<input type="text" name="name5" class="input01" />				</td>
              	<td>
    					<input type="text" name="email5" class="input02" size="40" />				</td>
              	</tr>
              <tr>
    				<td class="TableBG">&nbsp;</td>
              	<td colspan="2" class="TableBG">Your Message </td>
              	</tr>
              <tr>
    				<td colspan="3" height="5"></td>
              	</tr>
              <tr>
    				<td colspan="3" align="center">
              			<textarea name="comments" cols="65" rows="5" id="comments" style="width: 420px;"></textarea>          	</td>
              	</tr>
    			<tr>
    				<td class="TableBG">&nbsp;</td>
              	<td colspan="2" class="TableBG">Enter Verification Code</td>
              	</tr>
              <tr>
    				<td colspan="3" height="5"></td>
              	</tr>
    
    			<tr>
    <td colspan="3" align="center" valign="absmiddle"><img src="http://s.p4.hostingprod.com/@bestsafetyapparel.com/php/captcha.php" align="absmiddle">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="text" name="vercode" value="Enter Verification Code" onFocus="if(this.value=='Enter Verification Code') this.value='';" onBlur="if(this.value=='') this.value='Enter Verification Code';"/></td>
    </tr>
              
              <tr>
              	<td colspan="3" align="center">
              		<input type="submit" name="Submit" value="Send Email" class="button" />          	</td>
              	</tr>
            </table>
    	    </form>
          </td>
      </tr>
    </table>
    <script>
    function validate(frm)
    {
    	name = frm.sName;
    	email = frm.sEmail;
    	name1=frm.name1;
    	email1=frm.email1;
    
    	err_flag = 0;
    	
    	if (name.value == "" || !removeSpaces(name.value))
    		{
    			alert ("Please enter proper Name!");
    			name.value="";
    			name.focus();
    			return false;	
    		}
    		else if (email.value == "" || !validate_email(email.value))
    			{
    			alert ("Please enter proper Email!");
    			email.value="";
    			email.focus();
    			return false;	
    		}
    	
    		else if (name1.value == "" || !removeSpaces(name1.value))
    			{
    				alert ("Please enter proper Friend\'s Name!");
    				name1.value="";
    				name1.focus();
    				return false;	
    			}
    			else if (email1.value == "" || !validate_email(email1.value))
    				{
    					alert ("Please enter proper Friend\'s Email!");
    					email1.value="";
    					email1.focus();
    					return false;	
    				}
    
    }
    
    function validate_email(e)
    {
    	var str=e;
    	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    
    	if (!filter.test(str))
    		return false;
    	else
    		return true;
    }
    
    function removeSpaces(string) {
    	var tstring = "";
    	string = '' + string;
    	splitstring = string.split(" ");
    	for(i = 0; i < splitstring.length; i++)
    	tstring += splitstring[i];
    	return tstring;
    }
    </script>
    <br />
    <br />
    
    This way you can see if I had messed it up while making the minor changes like font size, table width, URLs etc.

    Let me know.

    Thanks
    Learner
    Last edited by learner99; 03-11-2011 at 09:22 AM. Reason: spelling & color

  9. #9
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Try the following changes:
    Code:
    	name = frm.sName;
    	email = frm.sEmail;
    	name1=frm.name1;
    	email1=frm.email1;
    
    	name = document[frm].sName;
    	email = document[frm].sEmail;
    	name1=document[frm].name1;
    	email1=document[frm].email1;
    ^_^

  10. #10
    Join Date
    Mar 2011
    Posts
    19
    Wolfshade! You are the man! I have moved the code within the <script> tags between the <head> tags and BINGO! It worked. Thanks much for your help my friend.

    But still the question remains, as how it is working on my other site.

    I have another issue now that the Captcha code is not being validated i.e even without entering the captcha code the form gets submitted. Any ideas? Thanks.

    Regards
    Learner
    Last edited by learner99; 03-11-2011 at 09:33 AM. Reason: spelling

  11. #11
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Did you make the suggested changes? That might be breaking the JS, allowing the form to submit.

    ^_^

  12. #12
    Join Date
    Mar 2011
    Posts
    19
    The changes you have suggested are for the code within the <script> tags which are now within the <head> tags.

    The captcha.php file calling is still within the <body> tags. I feel that the captcha code is working independent of the form code/script. I feel that the <script> is only verifying the form field inputs only and not looking at the captcha code.

    Am I right or am I going NUTS? Please point out as where exactly teh script is trying to validate the captcha code so that I would know.

    Let me know please. I just wanted to make sure before I make the changes to the script. Let me know.

    Thanks
    Learner

  13. #13
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    It's not that I think the validate function is interacting with the captcha; I _suspect_ that the form validation might be breaking, allowing the form to submit because the broken JS skips anything JS after the break.

    Just a suspicion. I could be totally wrong. But if the JS can't find the objects as you have them defined, it may be breaking.

    ^_^

  14. #14
    Join Date
    Mar 2011
    Posts
    19
    I want to understand/clarify whether we both are on the same page or not. Right now after moving the script to the head tags the total form field inputs namely name, email etc are being validated and proper message pops are working (in the event the user skips a field).

    The only thing which is not working is captcha code entry only which is irrelavant to JS (as per my limited knowledge). So my question is what do you think that is preventing the captcha code to validate the entry before allowing the form to submit.

    So are we both on the same page? I'm just clarifying here. If we are on the same page then I still do not understand how the script changes in head tags is going to affect the captcha or how is the JS is broken? Let me know please.

    Thanks
    Learner

  15. #15
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Did you move the captcha validation inside the HEAD tags, too? If not, that is most likely where the captcha is failing. If you did, then there is something else happening. Do the "submit/escape" again and see if there are any JS error messages for the captcha.

    ^_^

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles