加载页面时检查文本框的默认值更改 [英] check textboxes for change in value from default value when page loaded

查看:84
本文介绍了加载页面时检查文本框的默认值更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面上有两种形式.

I have a two forms on a page.

第一个有几个数量文本框,这些文本框在页面加载时填充了各自的默认值,这些值显然可以改变.页面上也可能有1、2、3或更多的这些文本框,因此脚本必须考虑到这一点.每个文本框将具有一个顺序名称"Quantity1,Quantity2等",并且ID也将相同.

The first one has several quantity text boxes that are populated with their respective default values on page load, which can obviously change. Also there may be 1, 2 ,3 or more of these text boxes on the page, so a script would have to account for this. Each text box will have a sequential name of "Quantity1, Quantity2, etc" and the id will be the same as well.

我要执行的操作是检查其中的任何一个是否都已更改为其默认值,并且在第二个表单中单击任一按钮时,它是执行第一个表单的按钮而不是第二个表单的按钮动作.

What I want to do it check to see if any of these have been changed from their default value and when either button is clicked on in the second form, it is to do the first form's button not the second form's button action.

现在,如果任何输入文本框中都没有更改,则第二个表单的按钮可以并且应该像平常一样工作.这是可能的,如果可以的话,最好使用jquery方法?

Now if there were no changes in any of the input text boxes, then the second form's buttons can and should act as normal. Is this possible and if so a jquery method is preferred?

注意:我在这里删除了很多不必要的代码,因此仅显示相关内容.

Note: I stripped out a lot of unnecessary code here so only the relevant stuff is shown.

<form method="POST" name="form" action="ShoppingCart.asp" onsubmit="if (typeof(Update_Hidden_State_Fields)=='function') Update_Hidden_State_Fields(); if (this.submitted) return false; else {this.submitted=true; return true;}">
<td><center><input type="text" maxlength="7" size="5" value="5" name="Quantity1" id="Quantity1"><center></td>
<td><center><input type="text" maxlength="7" size="5" value="2" name="Quantity2" id="Quantity2"><center></td> 
<td><center><input type="text" maxlength="7" size="5" value="5" name="Quantity3" id="Quantity3"><center></td>
<td width="135" align="right"><input border="0" type="image" id="btnRecalculate" name="btnRecalculate" src="v/vspfiles/templates/100/images/buttons/btn_recalculate.gif" alt="Recalculate Totals"></td>

这是当单击其中的任何一个按钮并且上面的表单中的任何输入框都已更改以执行第一个表单按钮动作时所用的表单.

Here is the form that when either button inside it is clicked on and any of the input boxes in the above forms have changed to do the first forms button action.

<form name="Proceed_To_Checkout_Form" method="post" action="https://www.dothisurl.com/login.asp">
<td><input type="image" src="v/vspfiles/templates/100/images/buttons/btn_checkout_guest.gif" name="btn_checkout_guest"></td>
<td><input type="image" src="v/vspfiles/templates/100/images/buttons/btn_checkout_guest.gif" name="btn_checkout_guest"></td>

推荐答案

我将尝试:

$(function(){
  $("[id^='Quantity']").each(function(){
    $(this).data('default', $(this).val());
  });

  $("[name='Proceed_To_Checkout_Form']").submit(function(){
    var hasChanged = false;
    $("[id^='Quantity']").each(function(){
      if($(this).val() != $(this).data('default')){
        hasChanged = true;
      }
    });
    if(hasChanged){
      $("#btnRecalculate").click();
      return false;
    }
  });
});

这篇关于加载页面时检查文本框的默认值更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆