Search code examples
javascriptjqueryhtmldrop-down-menuhref

drop down instead of a href


i want change this input to dropdown menu.

<a href="#" onclick="$('#pb1').progressBar(5);">5</a> |
<a href="#" onclick="$('#pb1').progressBar(60);">60</a> |
<a href="#" onclick="$('#pb1').progressBar(100);">100</a>

dropdown sample...(not work)

<form action="#" name="progress" onclick="$('#pb1').progressBar(10);">
   <select name="dropdown">
    <option name="radOne" value="$('#pb1').progressBar(5);" selected>5</option>
    <option name="radOne" value="$('#pb1').progressBar(60);">60</option>
    <option name="radOne" value="$('#pb1').progressBar(100);">100</option>
   </select>
</form> 

can anyone help me about change this structure?


Solution

  • This is how you should do it.

       <select name="dropdown" onchange="$('#pb1').progressBar(this.value);">
        <option name="radOne" value="5" selected>5</option>
        <option name="radOne" value="60">60</option>
        <option name="radOne" value="100">100</option>
       </select>
    

    Even like show, the practice of inline event handlers is not encouraged. Better approach is

    document.getElementByid("selectboxid").onchange = function() {
        $('#pb1').progressBar(this.value);
    };
    

    But, since you are already using jQuery

    $("#selectboxId").change(function() {
        $('#pb1').progressBar(this.value);
    });