Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jun 2011
    Posts
    33
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Javascript Form Validation Error Appearing

    Hi,

    I have placed a form validation script in my HTML and I think its all in the right place, however, when i load the page an error appears saying can not get object. Once I click past it, the form validation works as normal. Not sure how to get rid of this error.

    I have placed the link to the external validation script in the document head

    Any ideas?

    HTML
    Code:
    			<div class="mb_content">
    				<h2>Work</h2>
    				<div class="mb_content_inner">
    					<p>IMAGES COMING SOON.</p>
    				</div>
    			</div>
    			<div class="mb_content">
    				<h2>Contact</h2>
    				<p class="con_details_tel">tel: </p>
    				<p class="con_details_email">email: </p>
    				<div class="mb_content_inner">
    					<form id='contactus' name='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post' accept-charset='UTF-8'>
    						<fieldset >
    							<input type='hidden' name='submitted' id='submitted' value='1'/>
    							<input type='hidden' name='<?php echo $formproc->GetFormIDInputName(); ?>' value='<?php echo $formproc->GetFormIDInputValue(); ?>'/>
    							<input type='text'  class='spmhidip' name='<?php echo $formproc->GetSpamTrapInputName(); ?>' />
    
    							<div><span class='error'><?php echo $formproc->GetErrorMessage(); ?></span></div>
    							<div class='container'>
        						<label for='name' >Name: </label><br/>
        						<input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
        						<span id='contactus_name_errorloc' class='error'></span>
    							</div>
    							
    							<div class='container'>
        						<label for='email' >Email:</label><br/>
        						<input type='text' name='email' id='email' value='<?php echo $formproc->SafeDisplay('email') ?>' maxlength="50" /><br/>
        						<span id='contactus_email_errorloc' class='error'></span>
    							</div>
    
    							<div class='container'>
       							<label for='message' >Message:</label><br/>
        						<span id='contactus_message_errorloc' class='error'></span>
        						<textarea name='message' id='message'><?php echo $formproc->SafeDisplay('message') ?></textarea>
    							</div>
    
    							<div class='container'>
        						<input type='submit' name='Submit' value='Submit' />
    							</div>
    						</fieldset>
    					</form>
    					<script type='text/javascript'>
    
    
        				var frmvalidator  = new Validator('contactus');
        				frmvalidator.EnableOnPageErrorDisplay();
        				frmvalidator.EnableMsgsTogether();
        				frmvalidator.addValidation("name","req","Please provide your name");
    
        				frmvalidator.addValidation("email","req","Please provide your email address");
    
        				frmvalidator.addValidation("email","email","Please provide a valid email address");
    
        				frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");
    
    
    					</script>
    					
    				</div>
    			</div>
    		</div>
    Here is the start of the javascript that is producing the error:-

    Code:
    function Validator(frmname)
    {
        this.validate_on_killfocus = false;
        this.formobj = document.forms[frmname];
        if (!this.formobj)
        {
            alert("Error: couldnot get Form object " + frmname);
            return;
        }
    Can anyone help?

    Thanks

    nevblanc79

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Post the HTML code (not the PHP code, as we can not run a php code on our localhost without the PHP variables defined). Or post a link to a test page.

    By the way: what error? A "can not get object" is not sufficient (and probably not accurate).
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New Coder
    Join Date
    Jun 2011
    Posts
    33
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Have removed the php from the code.

    With regard to the error, when the page loads an alert box appears with the text ("Error: couldnot get Form object contactus)

    Thanks

    Niall

    Code:
    <div class="mb_content">
    				<h2>Work</h2>
    				<div class="mb_content_inner">
    					<p>IMAGES COMING SOON.</p>
    				</div>
    			</div>
    			<div class="mb_content">
    				<h2>Contact</h2>
    				<p class="con_details_tel">tel:</p>
    				<p class="con_details_email">email:</p>
    				<div class="mb_content_inner">
    					<form id='contactus' name='contactus' action='' method='post' accept-charset='UTF-8'>
    						<fieldset >
    							<input type='hidden' name='submitted' id='submitted' value='1'/>
    							<input type='hidden' name='' value='/>
    							<input type='text'  class='spmhidip' name='' />
    
    							<div><span class='error'></span></div>
    							<div class='container'>
        						<label for='name' >Name: </label><br/>
        						<input type='text' name='name' id='name' value='' maxlength="50" /><br/>
        						<span id='contactus_name_errorloc' class='error'></span>
    							</div>
    							
    							<div class='container'>
        						<label for='email' >Email:</label><br/>
        						<input type='text' name='email' id='email' value='' maxlength="50" /><br/>
        						<span id='contactus_email_errorloc' class='error'></span>
    							</div>
    
    							<div class='container'>
       							<label for='message' >Message:</label><br/>
        						<span id='contactus_message_errorloc' class='error'></span>
        						<textarea name='message' id='message'><></textarea>
    							</div>
    
    							<div class='container'>
        						<input type='submit' name='Submit' value='Submit' />
    							</div>
    						</fieldset>
    					</form>
    					<script type='text/javascript'>
    
    
        				var frmvalidator  = new Validator('contactus');
        				frmvalidator.EnableOnPageErrorDisplay();
        				frmvalidator.EnableMsgsTogether();
        				frmvalidator.addValidation("name","req","Please provide your name");
    
        				frmvalidator.addValidation("email","req","Please provide your email address");
    
        				frmvalidator.addValidation("email","email","Please provide a valid email address");
    
        				frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");
    
    
    					</script>
    					
    				</div>
    			</div>
    		</div>

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    HTML typo: you missed a quote:
    Code:
    <input type='hidden' name='' value='/>
    My advice is to use always double quotes to nest the attributes' values:
    Code:
    <input type="hidden" name="" value="" />
    // and so on
    And, in the fragment the code you have posted, you have an extra </div> end tag. Be careful. HTML errors might bring JavaScript and CSS errors as well.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New Coder
    Join Date
    Jun 2011
    Posts
    33
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Hi.

    Have added double quotes around all attributes but I still get the error message when the page loads.
    Last edited by nevblanc79; 07-11-2011 at 09:44 PM.

  • #6
    New Coder
    Join Date
    Jun 2011
    Posts
    33
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Do you need the javascript file as well?

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    No... All I can see is that you code does not see the form element. Which is weird, because when I simplified the code and run it locally, that worked. I still suspect that there is an error somewhere else, but you have so many other external codes, that I am not able to sense where... So far.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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