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 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2006
    Location
    Vienna, VA
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.forms error: no properties

    I've been tryin to figure out why I am getting this error for some time now. Any ideas?

    Code:
    <script language="Javascript">
    
    <!--
    var lead_id = "<?php echo $LeadID; ?>"
    
    if (lead_id > "") {
    	var state = "<?php echo $row['State']; ?>";
    	var confirmer = "<?php echo $row['Confirmer']; ?>";
    	var day = "<?php echo $row['ApptDay']; ?>";
    
    	if (state == "MD") {
    	  	alert("hi");
    		document.forms['form1'].state.options[0].selected = true;	
    	}
    }
    	
    //-->
    </script>
    state is equal to MD so I am getting the alert "hi", but it breaks right there and gives me this error.

    document.forms.form1 has no properties

    heres my form tag:
    Code:
    <form name="form1" id="form1" action="ticketformpro.php?LeadID=<?php echo $LeadID; ?>" method="post">

  • #2
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can't access an element before it has finished loading.

    Try this.
    Code:
    <script type="text/javascript"><!--
    var lead_id = "<?php echo $LeadID; ?>"
    window.onload = function() {
    	if (lead_id > "") {
    		var state = "<?php echo $row['State']; ?>";
    		var confirmer = "<?php echo $row['Confirmer']; ?>";
    		var day = "<?php echo $row['ApptDay']; ?>";
    
    		if (state == "MD") {
    		  	alert("hi");
    			document.forms['form1'].state.options[0].selected = true;	
    		}
    	}
    }
    //-->
    </script>
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #3
    New Coder
    Join Date
    Mar 2006
    Location
    Vienna, VA
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ahhhhhh, i can't believe i missed that!

    thanks a million.


  •  

    Posting Permissions

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