Tuesday, July 10, 2012

how to get all options of a select using javascript




<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

<script>
function getalllist(){
var len = document.addform.ddllist.length;  // alert(len);
var txt ='' ; // alert(len);
var values='';
arr=$("#ddllist option");
for(var i = 0; i < len ; i++) {
values+=document.addform.ddllist.options[i].value +"------" ; // form name  select box name
txt+=document.addform.ddllist.options[i].text +"------" ;
}
alert("All Values : "+ values);

alert("All Text Values : "+ txt);
}
</script>


<form   name="addform" method="post" action="#" id="addform">
<select multiple="multiple" name="ddllist" id="ddllist" >
<option value="php">PHP </option>
<option value="js">JAVASCRIPT </option>
<option value="css">CSS </option>
<option value="sql">MYSQL </option>

</select>

<input type="button" name="getvalue" value="ALL VALUE" onClick="getalllist();" />


</form>

No comments:

Post a Comment

If you Satisfied , Please Leave a comment