douya5331 2013-09-06 10:24
浏览 216

PHP如何获取按钮列表的值

I want a list of buttons in a form and on postback I'd like to interrogate the list to see what status the buttons are at (by background colour if you are interested.)

The following codes says that Buttonx is undefined

However using the text boxes it works fine.

In javascript I can get at the array of buttons - at least in my real program.

If this is not possible, and an explanation would be useful, does anyone have a workaround at how I can get at the buttons in my postback. (In the real code the buttons are dynamically created depending on an sql query list)

<?php      
  if ($_SERVER['REQUEST_METHOD'] == 'POST') {
      var_dump($_POST['Buttonx']);
  }
?>

<form name="RegisterStudents" action="" method="post">
  <button  type="submit" name="myButton">Submit</button>
  <!--
  <input type="text" name="Buttonx[]" id="B0" value="0" />
  <input type="text" name="Buttonx[]" id="B1" value="1" />
  <input type="text" name="Buttonx[]" id="B2" value="2" />
  <input type="text" name="Buttonx[]" id="B3" value="3" />
  --> 

  <button type="button" name="Buttonx[]" id="B0" >0</button>
  <button type="button" name="Buttonx[]" id="B1" >1</button>
  <button type="button" name="Buttonx[]" id="B2" >2</button>
  <button type="button" name="Buttonx[]" id="B3" >3</button>

</form>

Thanks Gordon

  • 写回答

3条回答 默认 最新

  • doutao8774 2013-09-06 10:28
    关注

    Using forms you cannot pass the form elements with type="button" to server their values are not passed to server instead you have to use any other type to send the information to server on client side you can access their values this is the default nature of html

    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试