Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
761 views
in Technique[技术] by (71.8m points)

php - calling javascript function from <select> onchange

I am trying to call a javascript function from the onchange attribute of the select tag ! My issue is that I am passing the name attribute of the select to the function which always go null.

<body>


<form action="" method="post">
<select name="slct" id="name" onchange="rohan('measurement_conversion', '<?php echo isset($_POST["slct"])?$_POST["slct"]:"null" ?>')">
<option value="yes" selected="selected"> yes </option>
<option value="nopes"> nopes </option>
<option value="may be"> May be </option>
<option value="dont know"> dont know </option>
</select>
</form>

<div id="abc">
</div>


</body>

And here my javascript function

<script>

function rohan(var1, var2)
{

    document.getElementById("abc").innerHTML=var1 + "            " + var2;
}

</script>   

It always prints null.. Any help will be appreciated !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

HTML:

<body>
    <form action="" method="post">
        <select name="slct" id="name" onchange="rohan(this.value)">
            <option>Select</option>
            <option value="yes" selected="selected"> yes </option>
            <option value="nopes"> nopes </option>
            <option value="may be"> May be </option>
            <option value="dont know"> dont know </option>
        </select>
    </form>
</body>

JS:

<script>
    function rohan(value)
    {
        //you can get the value from arguments itself
        alert(value);
    }
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...