Ignorant wannabe baffled - easy for you though

hello all, could really use a point in the right direction here PLEASE:

am showing or hiding a field in form depending upon a value in another field. this code works great, EXCEPT for first time through script.

<script type=“text/javascript”>
function writebox(form) {
if (form.repeat.value==‘0’) {
document.getElementById(“dDateE”).style.visibility = “hidden”;
} else {
document.getElementById(“dDateE”).style.visibility = “visible”;
}
}

so in addition I added this bit for onload, but it does not seem to be working, but how can it not be working? I mean it’s identical right?

window.onload = function writebox(form) {
if (form.repeat.value==‘0’) {
document.getElementById(“dDateE”).style.visibility = “hidden”;
} else {
document.getElementById(“dDateE”).style.visibility = “visible”;
}
}

the first function is on top of page and that onload bit is down in a part of the script I know is executed first time through.

I’m a newbie and lost and would really just a push in the right direction here!

many thanks,

mike

The problem is that the form value is not passed to it.

If you put your script at the bottom of the body (just before the </body> tag) you can leave the function as you started, and then call that function with a reference to the form.


<form id="descriptiveIdentifierForForm" ...>


function writebox(form) {
    ...
}

var form = document.getElementById('descriptiveIdentifierForForm');
writebox(form);

many thanks Paul !!

sorry about the late reply… forgot about my post here when I discovered that hiding that field solved one problem but caused another. I was better off sending a warning message and not accepting the value in the field. but thanks for your time and knowledge… I’m sure your reply will come in handy somewhere down the road…

hope Christchurch is doing well now.