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()
精彩评论