简体   繁体   English

单击提交按钮后如何识别特定文本字段中值的变化

[英]How to identify the change of value in a particular text field after submit button click

I want to update marks of a particular student in particular subject out of eight subjects. 我想更新八门科目中某个特定科目的学生的分数。 My question is how to identify that a particular text box value has been changed after clicking submit button, then the updation task is forwarded to the update.php. 我的问题是如何在单击“提交”按钮后确定特定的文本框值已更改,然后将更新任务转发到update.php。 Please give me your valuable answer. 请给我您宝贵的答案。 Thanks in advance. 提前致谢。

Since your button click event is occured on client side, you can identify it by client side scripting. 由于您的按钮单击事件发生在客户端,因此可以通过客户端脚本进行识别。

 <script lang='javascript'>
 $(document).ready(function(){
    $('#button_id').click(function(){
             /* Do whatever you want to do right here*/
    });
 });
 </script>

For identifying the change on text box after clicking submit button, first change the input type from submit to button as as soon as you click submit, it redirects the page. 为了在单击“提交”按钮之后识别文本框上的更改,请在单击“提交”后立即将输入类型从“ submit更改为“ button ,它将重定向页面。

<input type='button' onClick='your_function()' id='btn_submit' name='btn_submit' />
<input type='text' id='text_box' name='text_box' onchange='$('#flag_value_changes').val('1')' />
<input type='hidden' id='flag_value_changes' name='flag_value_changes' />
<script lang='javascript'>
function your_function()
{
         flag_value_changes = $('#flag_value_changes').val();
         if(flag_value_changes == 1)
            alert('Value has been changed');
         else
            alert('Value has not been changed');
}
</script>

the scripting language can help you in this situation.use javascript for the event of the submit button click. 脚本语言可以在这种情况下为您提供帮助。单击提交按钮时,请使用javascript。 do whatever you needed in that event..happy coding :) 做任何你需要的事情..快乐编码:)

As stated by hsuk. 正如hsuk所说。 You can do it on the client side using javascript. 您可以使用javascript在客户端进行操作。
I've provided an example using textarea and no inline javascript. 我提供了一个使用textarea且没有内联JavaScript的示例。

HTML 的HTML

<div>
  <textarea id= "math">Math</textarea>
  <textarea id= "english">English</textarea>
  <textarea id= "french">French</textarea>
  <textarea id= "spanish">Spanish</textarea>
  <input type="submit" value="submit"/>
</div>

And the following javascript(Using Jquery) 和以下javascript(使用jQuery)

$(document).ready(function(){
    var initialValues = [];
    var i = 0;
   //Gets values on load
    $("div textarea").each(function(){
        initialValues[i] = this.id+" had "+$(this).val(); 
        i++;
    });

   //Checks values on click
    $("input").click(function(){
    i = 0;
    $("div textarea").each(function(){
        value = initialValues[i].split(" ");
        if($(this).val() != value[2]){
            alert(value[0] + " was Changed.");   
        }
        i++;
        });
    });
});

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM