Click to See Complete Forum and Search --> : Dynamically add scripts...


Padrill
07-23-2003, 08:21 AM
Hi all,

I have a drop down menu a few times in a web site and thought to make it in a reusable script and not manually type the whole code each time. However I need to add drop down menus dynamically and the following doesn't work (I guess the script code is added but not executed - makes sense). Can anyone suggest any solutions?


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

function addMenu(span) {
span.innerHTML = '<script>dropDownDay("myDay")</scr'+'ipt>';
}
----------------------------
<span name="dyn" id="dyn"></span>
<input type="button" onMouseUp="addMenu(dyn)">

Khalid Ali
07-23-2003, 08:44 AM
if just need to add several drop downs to your document then I really qill question that why you need to do the way you are trying to do.It could be prety simple...

Or please explain that whats the purpose you want your code to serve with this logic...

Padrill
07-23-2003, 10:08 AM
I'll try to explain it better.

I'm doing a recruitment site and each candidate can dynamically add entries for past jobs and degrees. Each of those entries involve a date.

The candidate can add entries by clicking on a button (that updates the innerHTML of a <span>. In order to avoid typing a select with 31 options for days, a select with 12 options for months and a select with 100 options for years, I made it in a reusable script and tried to using the code above.

Is this any clear? Let me know if I need to be more specific.

Cheers