开发者

problems getting the values of a select element-

开发者 https://www.devze.com 2022-12-12 13:43 出处:网络
struggling to get the value of a selected item html- <select name=\"recommendFriend\" onChange=\"frie开发者_开发技巧ndWall(127);return false;\" id=\"recommendFriend\">

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

精彩评论

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