douyuqing_12345 2013-04-10 13:54
浏览 76
已采纳

更改表单提交的值?

I have a form with two different sets of fields in a form, one is billing address and one is shipping address.

I have written some jQuery so that you can hide the shipping form and it fills it in with the details in the billing form (if you are shipping to the same address).

This is my jQuery:

$('#reveal-shipping').click(function(){
    if( $('.wpsc_checkout_table.table-2').css('display') == 'none' ){

        $('.wpsc_checkout_table.table-2').slideToggle();
        $('.wpsc_checkout_table.table-2').find('input, select, textarea').val('');
        document.getElementById('reveal-shipping').innerHTML = 'Ship to my billing address ←';

    } else {

        //fields is an array containing an array of two selector strings, one for the billing form and one for the shipping.
        for ( i=0; i < fields.length; i++ ){
            thisval = $(fields[i][0]).val();
            $(fields[i][1]).val( thisval );
        }
        $('.wpsc_checkout_table.table-2').slideToggle();
        document.getElementById('reveal-shipping').innerHTML = 'Ship to a different address &rarr;';

    }
});

I'm wondering if I can run the for loop, which is the part that fills in the hidden input elements with values, onClick of the submit button, or if the values would have already been submitted by this point.

If not, when would be a good time to run this to ensure that the values are submitted correctly? maybe onunfocus? (please tell me the actual name for this)

Thanks in advance

  • 写回答

1条回答 默认 最新

  • dongzaotiao2863 2013-04-10 14:01
    关注

    You would be able to do this on the onClick event of the submit button or you can register a submit event on the form. Your events are run before the rest of the submission takes place. This is why you can call validation methods on the form and interrupt the submission by returning the value false.

    The 'onunfocus' event you are thinking of is blur

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

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装