how to get value using javascript in a select option box

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 35
Joined: Thu Jun 28, 2012 2:11 pm

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.value === value) {
elmnt.selectedIndex = i;

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

Post Reply