从< select>调用javascript函数不断变化 [英] calling javascript function from <select> onchange

查看:82
本文介绍了从< select>调用javascript函数不断变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从select标记的onchange属性调用javascript函数!我的问题是我将select的name属性传递给始终为null的函数.

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>

这是我的javascript函数

And here my javascript function

<script>

function rohan(var1, var2)
{

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

</script>   

它总是打印为null. 任何帮助将不胜感激!

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

推荐答案

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>

这篇关于从&lt; select&gt;调用javascript函数不断变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆