Can you enable a value in a form SELECT object by name?
I tried:
document.MyForm.MySelect['yes'].selected = true
but I got an error.
Can you enable a value in a form SELECT object by name?
I tried:
document.MyForm.MySelect['yes'].selected = true
but I got an error.
<option> elements can't have names.
Usedocument.forms[yourFormId].elements[yourElementId]to access an element, to minimise accidental collisions.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
DigitalBard (08-21-2008)
Thanks, I ended up just looping through the whole thing to select the items I needed:
Code:// sSel - name of the SELECT element in your form // sStr - elements of the SELECT you want selected, separated by commas function selectFromStr(sSel, sStr) { var o = document.getElementById(sSel); var sel = sStr.split(', '); for(i=0;i<o.length;i++) { o.options[i].selected = false for(s=0;s<sel.length;s++) { if (o.options[i].text==sel[s]) o.options[i].selected = true } } }
Hmm... note that that's a name you should be passing there, not an ID.
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Bookmarks