Post #215,928
7/21/05 2:27:04 PM
|
Need JavaScript bug help
In the following code, I am trying to get the value of the Select box. It works in Mozilla, but not IE. Any help would be apprecated. -t- \n{form name="mainform" method="post" action="somewhere.htm" target="_blank">\n\t{input type="submit" name="removebut" value="Press Me" \n\t\tstyle="width:200" onClick="buttonsClick('removebut')">\n\t{p>\n\t{select name="filterset">\n\t\t{option>foo\n\t\t{option>bar\n\t\t{option>foo bar\n\t{/select>\n\t{p>\n\t{input type="text" name="mybox">\n{/form>\n\n\n{script language="JavaScript">\n\t//-----------------------\t\n\tfunction buttonsClick(butName) { // button handler\n\t\tif (butName=='removebut') {\n\t\t\t/////alert(document.mainform.mybox.value);\n\n\t\t\tselectedPosition = \n\ndocument.mainform.filterset.selectedIndex;\n\n\t\t\tpicked = \n\ndocument.mainform.filterset.options[selectedPosition].value;\n\t\t\t\n\t\t\talert('test 3: pos=' + selectedPosition + ' value=' + \n\npicked);\n\t\t}\n\t}\n{/script>\n\n\n (Less-thans substituted with curlie braces)
________________ oop.ismad.com
|
Post #215,930
7/21/05 2:35:35 PM
|
Try closing the "option" tags
===
Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats]. [link|http://DocHope.com|http://DocHope.com]
|
Post #215,933
7/21/05 2:49:36 PM
7/23/05 12:10:15 AM
|
Tried that, no go
The original (with problem) had closings anyhow; I just rushed it for the sample when I substituted it with foo-bar stuff. I won't do it again.
________________ oop.ismad.com
Edited by tablizer
July 23, 2005, 12:10:15 AM EDT
|
Post #215,931
7/21/05 2:40:02 PM
|
Need a value attribute for the options
you've set the text for the options but assigned no value. \n <select name="filterset">\n <option value='foo'>foo\n <option value='bar'>bar\n <option value='foo bar'>foo bar\n </select>\n
|
Post #215,969
7/21/05 4:44:54 PM
|
Thanks, it worked!
However, it does bring up a couple of questions:
1. Why did it work in Mozilla without the Value tag?
2. How does one reference the description text in JS?
________________ oop.ismad.com
|
Post #215,970
7/21/05 4:53:28 PM
|
Mozilla probably defaults
Means that <option> is probably not treated the same as <option value=''>. Anyhow, it's not a behavior that should be relied upon. The text can be retrieved by using .text instead of .value. document.mainform.filterset.options[selectedPosition].text;
|
Post #216,187
7/23/05 12:12:16 AM
|
Can anybody recommend a good on-line JavaScript reference?
My dot-com-fire-sale books are getting outdated. Thanks for the tips.
________________ oop.ismad.com
|
Post #216,191
7/23/05 12:24:11 AM
|
Wikipedia?
[link|http://en.wikipedia.org/wiki/JavaScript|JavaScript] and [link|http://en.wikipedia.org/wiki/Ecmascript|ECMAScript]. They seem to be decent references with pointers to other sources.
HTH.
Cheers, Scott.
|
Post #216,192
7/23/05 12:32:39 AM
|
Various References
I generally fallback on the O'Reilly [link|http://www.oreilly.com/catalog/dhtmlref2/|DHTML] and [link|http://www.oreilly.com/catalog/jscript4/|JavaScript] books. [link|http://www.dannyg.com/pubs/jsb/|Javascript Bible] is also good but after reading it, I rarely fall back to it for reference purposes. Anyhow, if you're in the market, those are probably the three best.
There's lots of web resources as well, but I usually just google and end up at random places. Two that I've bookmarked but don't use regularly are [link|http://javascript-reference.info/|Javascript crib] and [link|http://webref.info/default.asp?|WebRef].
|
Post #216,256
7/24/05 11:18:24 PM
|
Oldie but goodie
[link|http://wp.netscape.com/eng/mozilla/3.0/handbook/javascript/|http://wp.netscape.c...dbook/javascript/]
===
Purveyor of Doc Hope's [link|http://DocHope.com|fresh-baked dog biscuits and pet treats]. [link|http://DocHope.com|http://DocHope.com]
|
Post #215,934
7/21/05 2:55:42 PM
|
For future reference, just backslash escape the <
Regards,
-scott anderson
"Welcome to Rivendell, Mr. Anderson..."
|
Post #215,948
7/21/05 3:21:23 PM
|
LRPD: But don't get all fretty-pants on us.
"Whenever you find you are on the side of the majority, it is time to pause and reflect" --Mark Twain
"The significant problems we face cannot be solved at the same level of thinking we were at when we created them." --Albert Einstein
"This is still a dangerous world. It's a world of madmen and uncertainty and potential mental losses." --George W. Bush
|