根据提交按钮更改隐藏输入字段的值 [英] changing value of hidden input fields depending on submit button

查看:22
本文介绍了根据提交按钮更改隐藏输入字段的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面中有多个表单,根据隐藏的输入值,调用了不同的部分.

I have multiple forms in my page and depending on the hidden input value, different sections are called.

现在我的问题是,我的一个表单中有 2 个输入按钮,根据我单击的按钮,我需要发送适当的隐藏输入类型,

Now my issue is, I have 2 input buttons in one of my forms, and depending on what button I click i need to send the appropriate hidden input type,

例如在下面的表格中.如果我点击生成密码按钮,我想要目标值(隐藏输入字段的值)作为 generate_password

For example in the below form . If i click on Generate password button, I want the target value(the value of the hidden input field) as generate_password

如果我点击锁定密码,我希望目标值是 user_locked.这是我的代码.

If I click on Lock Password I want the target value to be user_locked. Here is my code.

    puts "<input type=\"hidden\" name=\"target\" value=\"user_locked\">"
    puts "<tr><td colspan='4'> New User request Review</td></tr>"
    puts "<tr><td><label for=\"full_name\"> Full Name </label></td>"
    puts "<td><input type=\"text\" value =\"$name\" name =\"full_name\" readonly=\"readonly\"></td>"

    puts "<tr><td><input type=\"button\" value=\"Generate Password\" onclick=\"if(confirm('Are you user you want to add this user?')){submit()};\"></td>"
    puts "<td><input type=\"button\" value=\"Lock User\" onclick=\"if(confirm('Are you user you want to add this user?')){submit()};\"></tr>"

基本上我根据隐藏字段调用不同的函数,

well basically I am calling different functions depending upon the hidden field,

set target "";      catch { set target $CGI_DATA(target) }
switch $target {
    "confirm"   { set id [UpdateUserData $id] }
    "user_locked    { DeleteUser $id }
    "user_confirmed"        { NewUserConfirmed}
    "newuser"   { NewUserReview }
    default     { }
}

推荐答案

onclick 事件的代码可以在确认时执行此操作,而不仅仅是提交表单.如果您使用 jQuery:

The code to your onclick event could do that when confirming instead of just submitting the form. If you use jQuery:

if(confirm('Are you user you want to add this user?')){
    $("input[name=target]").val('Generate password');
    submit();
}

另一个输入按钮应该非常相似.

The one for the other input button should be very similar.

您也有可能知道按下了哪个按钮以另一种方式提交表单.如果我没记错的话,在 PHP 中至少按钮的名称是通过 _REQUEST 变量传递的.

It is also possible that you have a way of knowing which button was pressed to submit the form another way. If I remember correctly, in PHP at least the name of the button is passed through in the _REQUEST variable.

这篇关于根据提交按钮更改隐藏输入字段的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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