dhoran
07-11-2007, 03:32 PM
I've been hacking at this for a while and managed to get this script to work in IE & FF on Windows, but it fails on Mac/Safari. The script will dynamically add a SELECT control to a table, and I want it to fire onchange calling another function to toggle a textbox visible (display=block|none). Here is a snippet:
...
var SectorCell = document.createElement("td");
var SectorCombo = document.createElement("select");
SectorCombo.id = "D1_Sector_" + currD1Idx;
SectorCombo.setAttribute("name","D1_Sector[]");
SectorCombo.onchange = "D1_checkother('D1_Sector_" + currD1Idx + "','D1_Sector_Other_" + currD1Idx + "')";
var sectorOnChangeHandler = new Function(SectorCombo.onchange);
if (SectorCombo.addEventListener) {
SectorCombo.addEventListener('change', sectorOnChangeHandler, false );
} else if (SectorCombo.attachEvent) {
SectorCombo.attachEvent('onchange', sectorOnChangeHandler);
}
SectorOther = document.createElement("input");
...(create and attach option elements)...
SectorCell.appendChild(SectorCombo);
SectorCell.appendChild(SectorOther);
The "D1_checkother(src,tar)" function simply locates the element and changes the style property as above. To view this script in action go to http://itc.hbg.psu.edu/projects/KAZ/development/enrollment/enrollment_form.php and try the first Demographics question (select Other to make the textbox visible).
I've added a lot to accommodate cross-browser issues, and I would like to have the same functionality for our Safari users.
I've done a bit of Javascript before, but this is headfirst into serious DOM manipulation via JS. Any help diagnosing this issue would be greatly appreciated!
Thanks!
...
var SectorCell = document.createElement("td");
var SectorCombo = document.createElement("select");
SectorCombo.id = "D1_Sector_" + currD1Idx;
SectorCombo.setAttribute("name","D1_Sector[]");
SectorCombo.onchange = "D1_checkother('D1_Sector_" + currD1Idx + "','D1_Sector_Other_" + currD1Idx + "')";
var sectorOnChangeHandler = new Function(SectorCombo.onchange);
if (SectorCombo.addEventListener) {
SectorCombo.addEventListener('change', sectorOnChangeHandler, false );
} else if (SectorCombo.attachEvent) {
SectorCombo.attachEvent('onchange', sectorOnChangeHandler);
}
SectorOther = document.createElement("input");
...(create and attach option elements)...
SectorCell.appendChild(SectorCombo);
SectorCell.appendChild(SectorOther);
The "D1_checkother(src,tar)" function simply locates the element and changes the style property as above. To view this script in action go to http://itc.hbg.psu.edu/projects/KAZ/development/enrollment/enrollment_form.php and try the first Demographics question (select Other to make the textbox visible).
I've added a lot to accommodate cross-browser issues, and I would like to have the same functionality for our Safari users.
I've done a bit of Javascript before, but this is headfirst into serious DOM manipulation via JS. Any help diagnosing this issue would be greatly appreciated!
Thanks!