diego jimenez diego jimenez - 7 months ago 34
Javascript Question

How to update and recall a javascript function after select different value from select dropdown

Hi i have this javascript at bottom of my page.

var e = document.getElementById("path_chooser");
var path= e.options[e.selectedIndex].value;

function update()
{
imgObj = document.getElementById('img1');
if (!isChrome) imgObj.src = img.src;
img.src = "cams/camera1.php?canal="+path+"&t="+(unique_name++);
if (originalWidth == 0)
{........ bla bla bla


i have a select dropdown

<select id="path_chooser" >
<option value="1">camera1</option>
<option value="2" selected="selected">camera2</option>
<option value="3">camera3</option>
</select>


this javascript updates a camera image in a div, it works ok, now i need that the javascript updates the var "path" when user changes the selected camera.

i get the var path updated when i change the selection, but the div is not refreshed, please tell me how to do it.

Thanks a lot

Diego

Answer

Here is an example for handle onchange event for a drop down box:

<select id="path_chooser" onchange="getOption(this)">
            <option value="1">camera1</option>
            <option value="2" selected="selected">camera2</option>
            <option value="3">camera3</option>
            </select>

 function getOption(v)
 {
   var path= v.options[v.selectedIndex].value;
   imgObj = document.getElementById('img1');
   if (!isChrome) imgObj.src = img.src;
   img.src = "cams/camera1.php?canal="+path+"&t="+(unique_name++);
   .............................
 }