onchange事件的选择框 [英] onchange event of select box

查看:143
本文介绍了onchange事件的选择框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用selectbox从数据库中显示enterpirses的列表。但onchange事件不会触发。但是当我手动一次把查询字符串的值,然后开始工作。我不明白为什么会发生这种情况。



我是新来的javascript和php,请告诉我解决方案。

 < select id =enterpriseboxonchange =javascript:valueselect()> 
< option value = - > - < / option>

<?php foreach($ enterprise as $ val){?>
< option value =<?php echo $ val ['customer_id'];?>><?php echo $ val ['customer_name']?>
< / option>
<? }?>

< / select>

和我的javascript是 -

  function valueselect()
{
var i = document.getElementById('enterprisebox');
var p = i.options [i.selectedIndex] .value;
// alert(p);
window.location.href =channelinformation.html?selected =+ p;


解决方案

onchange =javascript:valueselect()替换onchange =valueselect(this.value);

 函数valueselect(myval)
{
window.location.href =channelinformation.html?selected =+ myaval;
}

您可以直接使用

  onchange =window.location ='channelinformation.html?selected ='+ myaval


I am using a selectbox to display the list of "enterpirses" from the database. But the onchange event is not triggering. But when i manually once put the value of querystring then it starts working. I dont understand why it is happening.

I am new to javascript and php, kindly suggest me the solution to this.

<select id="enterprisebox" onchange="javascript:valueselect()" >
    <option value="-">-</option>

    <?php foreach($enterprise as $val) { ?>
    <option value="<?php echo $val['customer_id'];?>"><?php echo $val['customer_name']?>
    </option>
    <? } ?>

</select>

and my javascript is--

function valueselect()
{
    var i = document.getElementById('enterprisebox');
    var p = i.options[i.selectedIndex].value;
    //alert(p);
    window.location.href = "channelinformation.html?selected="+p;
}

解决方案

onchange="javascript:valueselect()" replace with onchange="valueselect(this.value);"

function valueselect(myval)
{
      window.location.href = "channelinformation.html?selected="+myaval;
}

You Can Use Directly

onchange="window.location='channelinformation.html?selected='+myaval"

这篇关于onchange事件的选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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