Document.write(my_var); refuses to change! NEED help. even insults are welcome!

oh wise ones… your guidance is desperately needed!

any thoughts at all PLEASE would be greatly appreciated!! even insults are welcome!! this should be easy as pie, but I’ve been banging my head on the wall and going around in circles all morning! spent a long time on “the Google” looking for my problem. all I found was maybe I shouldn’t be using document.write, but found no alternative. plus it works (the first time through anyways).

I have a pop up window where users schedule an event to post on a calendar. events occur once, or repeat (say weekly, for example).

here is what I need the script to do:
check a drop down form to see if user wants event to repeat or not. default is not. this part is working fine.
if event repeats we HIDE a time input form. this part is working fine.
if event does NOT repeat we SHOW the time input form. this part working fine.

but what I thought would be the simplest part is not working. my_var is just a lousy string that I want to write. it should show “End Date” if event does not repeat, or “Repeat Until” if event does repeat. but I can’t get the damn thing to work. I know just about zero javascript. I understand it is browser side, not server side and that’s about it.

sorry about no link for you guys to try the script yourselves. this thing is running on my localhost. not ready for prime-time :slight_smile:

THANK YOU for your valuable time. here is the offending code:

<head>
<script type=“text/javascript”>
<!–

repeat_var=“End Date:”;

function writebox(form) {
if (form.repeat.value==‘0’) {
repeat_var=“End Date:”;
document.getElementById(“dTimeE”).style.visibility = “visible”;
} else {
repeat_var=“Repeat Until:”;
document.getElementById(“dTimeE”).style.visibility = “hidden”;
}
}
//–>
</script>
</head>

<body>
<td>
<select name=“repeat” title=“Select how often” id=“repeat” onchange=“writebox(this.form)”>
<option value=“0”<?php echo (!$_POST[“repeat”]) ? ’ selected=“selected”>’ : “>”; echo $xx[“evt_none”]; ?></option>
<option value=“1”<?php echo ($_POST[“repeat”] == “1”) ? ’ selected=“selected”>’ : “>”; echo $xx[“evt_daily”]; ?></option>
<option value=“2”<?php echo ($_POST[“repeat”] == “2”) ? ’ selected=“selected”>’ : “>”; echo $xx[“evt_weekly”]; ?></option>
<option value=“3”<?php echo ($_POST[“repeat”] == “3”) ? ’ selected=“selected”>’ : “>”; echo $xx[“evt_monthly”]; ?></option>
<option value=“4”<?php echo ($_POST[“repeat”] == “4”) ? ’ selected=“selected”>’ : “>”; echo $xx[“evt_yearly”]; ?></option>
</select>
</td>

<td><script type=“text/javascript”>document.write(repeat_var);</script></td>

<td id=“dTimeE”<?php echo $hidden; ?>><input type=“text” title=“click clock icon or enter HH:MM XM” name=“end_time” id=“end_time” value=“<?php echo $_POST[“end_time”]; ?>” size=“6” /><a href=“#” onclick=“tPicker(‘end_time’)”><img src=“images/flipped_clock.png” alt=“End Time” /></a>

</body>

A document.write statement runs once while the page is first loading - since you have server side code there the document.write is better replaced by a PHP echo statement which serves exactly the same purpose.

If you want to actually update the page after it has loaded you need to use either innerHTML or the appropriate DOM commands. If you want to update a part of something you have already updated or part of a table then even innerHTML doesn’t work.

THANK YOU SIR !!

oh so very close now. script is working great EXCEPT for initial page load - there the variable is empty and nothing is printed.
new code:
function writebox(form) {
var labelTD = document.getElementById(“otherLabel”);
if (form.repeat.value==‘0’) {
labelTD.innerHTML=“End Date”;
document.getElementById(“dTimeE”).style.visibility = “visible”;
} else {
labelTD.innerHTML=“Repeat Until”;
document.getElementById(“dTimeE”).style.visibility = “hidden”;
}
}

&lt;td id="otherLabel"&gt;&nbsp;&lt;/td&gt;

tried this to get page to load with “End Date”, but no dice. can you educate me just one more time me please…

var labelTD = document.getElementById(“otherLabel”);
labelTD.innerHTML=“End Date”;

function writebox(form) {
var labelTD = document.getElementById(“otherLabel”);
if (form.repeat.value==‘0’) {
labelTD.innerHTML=“End Date”;

	document.getElementById("dTimeE").style.visibility = "visible";
} else {
	labelTD.innerHTML="Repeat Until";
	document.getElementById("dTimeE").style.visibility = "hidden";
}

}

OR is that what document.write is for… just the page load. should I put that back in? is that best practice?