dragon4587 2013-05-30 01:38
浏览 78
已采纳

用php选择框Onchange:autosubmit()选项

So it's like I have a selectbox, with while loop as option as I want to bring out the options from database, is it possible to click on the option and link?

The while loop is like this

while ($row = mysqli_fetch_assoc($result0))
{
$option .= '<option value="'.$row['id'].'">'.$row['Font_Family'].'</option>';
}

This is the select box

<select id='font' style="width:100px;" onchange="autosubmit();">
            <option value ="0">Select</option>

But on clicking the option I want to link it to

 font.php?id={id that is being pointed to}

How can I do this?

  • 写回答

1条回答 默认 最新

  • dongyan1625 2013-05-30 01:55
    关注

    Use Javascript to call the onchange.

    Between the header tags, put:

      <script type="text/javascript">
        function autosubmit() {
          window.location="font.php?id="+document.getElementById("font").value;
        }
      </script>
    

    View the working jsbin: http://jsbin.com/uwuyoz/1/

    Please note, you'll have to uncomment the window.location. I simply have it 'alerting' now. But all the code is there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 Keil编译时报错"no source": Error: #5: cannot open source
  • ¥50 操作系统时间无法更新
  • ¥20 Windows11, usb转hdmi,外接显示器无反应
  • ¥20 怎么在JavaFx的TableView中动态地添加数据。
  • ¥15 MFC里的工具栏按钮图标使用外部图片
  • ¥15 如何在 llama.cpp 服务器中实现用户登录功能的优化方案?(语言-c++)
  • ¥15 有会用octave 的吗,急!代做!好偿!
  • ¥15 有一套同城小程序源码,Uniapp前端,php+html+mysql后端 ,能不能教我搭建起来可以运行,我不知道怎样操作
  • ¥15 mac调用java.io接口无法在根目录生成文件
  • ¥15 java微服务节点假死,网关路由时长延迟