duangan6133 2009-02-20 01:25
浏览 33
已采纳

IE 6和多个按钮元素都发送它们的名称和值

When using multiple button elements in a form, I realised that IE7 sends the innerHTML instead of the value of the button. All good I thought, I'll simply change my PHP code to this

<?php

if (isset($_POST['button-name'])) {
   add_product_to_cart(2);
}

?>

Now my old friend IE6 is going a little step further at being a nuisance. It sends all of the button elements regardless of which one I click. For example, I have 3 button elements named 'mint', 'near-mint' & 'standard'. A quick print_r($_POST) tells me that all 3 names have been submitted.

I guess to remedy this will be some JavaScript, not the most elegant situation, but I can imagine that the average user still using IE6 is not bright enough to turn off their JavaScript.

How can I remedy this?

  • 写回答

3条回答 默认 最新

  • dsgd4654674 2009-02-20 01:56
    关注

    I found a solution at http://www.codecomments.com/JavaScript/message756646.html

    All credit to the author on that page.

    Per request, here is the code

    function buttonfix(){
    var buttons = document.getElementsByTagName('button');
    for (var i=0; i<buttons.length; i++) {
    buttons[i].onclick = function () {
    for(j=0; j<this.form.elements.length; j++)
    if( this.form.elements[j].tagName == 'BUTTON' )
    this.form.elements[j].disabled = true;
    this.disabled=false;
    }
    }
    }
    window.attachEvent("onload", buttonfix);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)