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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    html form messing up javascript

    This is the weirdest thing I've come across in awhile. I have some code that formats a input field for a date format. This code runs fine on all browser when the form tag isn't wrapped around the inputs. The second I wrap the form tag around the inputs everything messes up. The Javascript error I'm getting is "Object doesn't support this property or method." on line 45 which is the line of the date input field. I'm totally clueless what I'm doing wrong here. And so I'll leave it up to you the wonderful community to give me some help.

    Thanks,
    Jon W


    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
    <html leng="en">
    <head>
    <script type="text/javascript">
    	function dob(val,e) {
    		if(e.keyCode != 8) {
    			if(val.length == 2 || val.length == 5) {
    				if(val.match(/[\/]$/) != "/") {
    				document.getElementById('dob').value += "/";
    				}
    			}
    			var regex = /[a-zA-Z]|\+|\-|\&|\\|\(|\)|\%\|\$|\#|\@|\*|\_|\?|\>|\<|\,|\./;
    			if(val.match(regex)) {
    				newStr = val.replace(regex,'');
    				document.getElementById('dob').value = newStr;
    			}
    		}
    	}
    </script>
    <style type="text/css">@import url(/css/home.css);</style>
    </head>
    <body>
    <div id="wrapper">
    <div id="header">
    <div id="logo"><a href="/index.php"><img src="/images/logo.png" /></a></div>
    </div>
    <div id="container-arrow"></div>
    <div id="container">
    	<img src="/images/no_image.png" />
    	
    	<div id="sign-container">
    	<span class="sign-header">
    		Sign Up
    	</span>
    	<div id="sign-arrow-up"></div>
    	<div id="sign-content">
    	<form method="post" action="/account/index.php" name="sign">
    		<label for="email">Email</label><input name="email" class="sign-inputs" type="text" />
    		<p>
    		</p>
    		<label for="password">Password</label><input name="password" class="sign-inputs" type="password" />
    		<p>
    		</p>
    		<label for="dob">Date Of Birth</label>
    		<input type="text" name="dob" style="text-align:center;" maxlength="10" class="sign-inputs" id="dob" value="MM/DD/YYY" onkeyup="dob(this.value,event);" onkeydown="dob(this.value,event);" onfocus="if(this.value=='MM/DD/YYY') this.value='';" title="MM/DD/YYY" />
    		<p>
    		</p>
    		<input name="submit" type="submit" class="sign-submit" value="Sign Up" />
    	</form>
    	</div>
    	</form>
    	</div>
    </div>
    </div>
    </body>
    </html>

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    IE uses window.event and does not get an event passed in.

    Code:
    function dob(val,e) {
        e = e || window.event;
        var key = e.keyCode || e.which;
        if(key != 8) {
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Hrmm... Thanks for the tip. However, I'm still having the same exact error as before.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,983
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    You are using dob both as the name/id of a textfield and as the name of a function.

    A child of five would understand this. Send someone to fetch a child of five.
    Groucho Marx

  • #5
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Haha... Cool, that was the problem. Thanks for the help!

    Jon W,


  •  

    Posting Permissions

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