dragonsun00000 2014-08-27 01:49
浏览 25

重用html表单值

I have a two forms in the same page. The first form is just a abbreviated version of the second form, i.e., the first form has three fields and the second form has the same three fields plus an additional eight fields.

When the submit button is pressed on the first form it navigates to the second form location. Is it possible to use the values from the first form to populate the three repeated values on the second form?

  • 写回答

3条回答 默认 最新

  • dongshanya2008 2014-08-27 01:58
    关注

    You can utilize the "submit" event of the first form (or just the "click" event for a non-submitting button). Capture the value of the first three fields with Javascript, and set the value of the next form's fields. Then you can transition to the next form.

    $('#form-1').submit(function(e) {
        // Set the value of the 2nd form to the values of the 1st form's fields
        // Add as many as you like. You can also do validation here.
        $('#field-1-ext').val( $('#field-1').val() );
        $('#field-2-ext').val( $('#field-2').val() );
    
        // Show the second form, hide the first
        $('#form-1').fadeOut();
        $('#form-2').fadeIn();
    
        // Prevent normal form submission (navigating away from page)
        e.preventDefault();
        return false;
    });
    

    Here is a JSFiddle example: http://jsfiddle.net/muof06a0/1/

    评论

报告相同问题?

悬赏问题

  • ¥15 BV260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序