...

View Full Version : document.forms error: no properties



mattyboi
04-28-2006, 10:47 PM
I've been tryin to figure out why I am getting this error for some time now. Any ideas?



<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:


<form name="form1" id="form1" action="ticketformpro.php?LeadID=<?php echo $LeadID; ?>" method="post">

Kravvitz
04-28-2006, 10:51 PM
You can't access an element before it has finished loading.

Try this.

<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>

mattyboi
04-28-2006, 10:59 PM
ahhhhhh, i can't believe i missed that!

thanks a million.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum