开发者

problems getting the values of a select element-

struggling to get the value of a selected item

html-

<select name="recommendFriend" onChange="frie开发者_开发技巧ndWall(127);return false;" id="recommendFriend">



var user = document.getElementById("recommendFriend").getAttribute("value")

im using JS on facebook


Select boxes are a bit tougher to get the value of...

 document.nameOfForm.idOfSelect.options[document.nameOfForm.idOfSelect.selectedIndex].value

should get you where you want to be.


<select /> tags have no value attribute. Instead, you should use the selectedIndex or the value property.

var selectElem = document.getElementById("recommendFriend");
var user = selectElem.value;

I can't remember if all modern browsers support the value property (I'm pretty certain they do), but if not, then do this:

var selectElem = document.getElementById("recommendFriend");
var selectedIndex = selectElem.selectedIndex;
var user = selectElem.options[selectedIndex].value;


i have found the problem- yet again facebook has its own ideas about JS- the solution was

var selectElem = document.getElementById("recommendFriend");
var user = selectElem.getValue()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜