Selected Value From Select Box In Javascript March 31, 2024 Post a Comment I want to get the value of the select box using javascript i have the following code. html part Solution 1: You missed the '.marked':var all = document.myform.marked.options[document.myform.marked.selectedIndex].value; alert(all); CopySolution 2: var e = document.getElementById("ctl00_cphContent_ddlVoteType"); var strOption = e.options[e.selectedIndex].value; Copyworking fine for me. please check Solution 3: Try<formmethod="POST"name="me"><selectsize="1"name="D1"onChange="checkData()"><optionvalue="99">Default</option><optionvalue="1">1</option><optionvalue="2">2</option><optionvalue="3">3</option><optionvalue="4">4</option></select><inputtype="submit"value="Submit"name="B1"><inputtype="reset"value="Reset"name="B2"></p></form><scriptLanguage="JavaScript"><!-- functioncheckData() { var myTest = me.D1.options[me.D1.options.selectedIndex].value; ///or me.D1.options[me.D1.selectedIndex].valuealert(myTest); } </script>CopySolution 4: the following code is working for meJava Script :functioncheckdata() { alert(document.getElementById('marked').value); } CopyHTML :<selectname="marked"id="marked"onchange="checkdata(this);"><optionvalue="">SELECT</option><optionvalue="all">ALL</option><optionvalue="none">NONE</option><optionvalue="read">READ</option><optionvalue="unread">UNREAD</option></select>CopySolution 5: get the selected value onchange<scriptLanguage="JavaScript">functioncheckdata(marked){ var marked_value = marked.value; // store the selected value marked_value alert(marked_value); // do further processing with "marked_value" if needed } </script>Copyfor option selects you don't use "checked" that is for radio and checkbox Share Post a Comment for "Selected Value From Select Box In Javascript"
Post a Comment for "Selected Value From Select Box In Javascript"