Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

how to get value using javascript in a select option box

Links for php scripts

Moderators: macek, egami, gesf

how to get value using javascript in a select option box

Postby phpkiller » Thu Nov 07, 2013 6:37 am

First use this javascript code block:
<script type="text/javascript">
function selectItemByValue(elmnt, value){

for(var i=0; i < elmnt.options.length; i++) {
if(elmnt.options[i].value === value) {
elmnt.selectedIndex = i;
break;
}
}
}
</script>

This is how u can call it:

selectItemByValue(document.getElementById('id_of_element'), value_of_select_box);

This value of select box should match with value in select box in HTML
phpkiller
New php-forum User
New php-forum User
 
Posts: 31
Joined: Thu Jun 28, 2012 2:11 pm

Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron