Click to See Complete Forum and Search --> : Dynamically created drop down menu


Padrill
04-24-2003, 05:48 AM
I'm trying to dynamically create a drop down menu for date input using the following function:

<head>
<script language="JavaScript1.2">
function dropDownDay(strName) {
document.write('<select name="' + strName + '">');
for (i=1; i<=31; i++) {
document.write('<option value="' + i +'">' + i + '</option>');
}
document.write('</select>');

return true;
}
</script>
</head>

I call this function using:

<body>
<form name="birthdateForm">
<script language="JavaScript1.2">
dropDownDay(birthDay);
</script>
</form>
</body>

Can I do that and still be able to access the value of the selectedIndex?

document.birthdateForm.birthDay doesn't seem to exist.

Does anyone have any suggestions? Thanx.

gil davis
04-24-2003, 06:26 AM
It might work better if you usedropDownDay("birthDay");(note the quotes).

Padrill
04-24-2003, 07:16 AM
Oops, sorry. That was a typo in the question. I did include the quotes in the script. Any more ideas?

Padrill
04-24-2003, 07:35 AM
Apologies my bad. document.birthdateForm.birthDay does get created.

I used to refer to it from within the birthdateForm as this.birthDay and that doesn't work.

I may sound like an idiot but could anyone explain why this.birthDay doesn't work?

AdamBrill
04-24-2003, 07:52 AM
Well, the reason would be because "this" wasn't referring to the form. If you want to use something like that, you could do this:

frm=document.birthdateForm;

frm.birthDay would then refer to the element. I hope that helps... ;)