如何保存和检索只读类​​型的文本框的值? [英] How to save and retrieve values of text box of type read only?

查看:70
本文介绍了如何保存和检索只读类​​型的文本框的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算学生的费用总额,我得到费用的价值,当我给予折扣,特许给在数据库中重视商店的学生。



当我我保存已禁用文本框的值,它没有保存在数据库中。

解决方案

不确定您的业务规则是什么,但禁用输入框没有值类型文本。如果你在下面运行我的例子,你会看到提交lname值没有通过,即使我已经设置了它。



<!DOCTYPE html>

< html>

< body>



< form action =demo_form.asp >

名字:< input type =textname =fname>< br>

姓氏:< input type =text value =fdsaname =lname已停用>< br>

< input type =submitvalue =提交>

< / form>



< / body>

< / html>





我的解决方案是将文本框设置为只读。这将不允许用户更改值。



如果您在JavaScript中将文本框设置为禁用,则设置后续解决方案禁用文本框到隐藏值,以便您可以访问该值,即使文本框已禁用且无价值。



<!DOCTYPE html>

< html>

< body>



< form action =demo_form.asp>

名字:< input type =textname =fname>< br>

姓氏:< input type =textname =lname已禁用>< br>

< input type =hiddenname =lnameIfDisabledvalue =Pizza>

< input type =submitvalue =Submit>

< / form>



< / body>

< / html>



如果这样可以解决您的问题,请将问题标记为已回答。感谢。

I want to calculate fee total of student,I getting values of fee and when i give discount,concession to student that values store in database.

when i am saving values of disabled text box,It was not saving in database.

解决方案

Not sure what your business rules are, but there is no value for a disabled input box of type text. If you run my example below, you'll see on submit the lname value is not passed, even though I've set it.

<!DOCTYPE html>
<html>
<body>

<form action="demo_form.asp">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" value="fdsa" name="lname" disabled><br>
<input type="submit" value="Submit">
</form>

</body>
</html>


My solution would be to set the textbox to readonly. This will not allow the user to change the value.

A subsequent solution if you are setting the textbox to disabled in JavaScript, then set the value of the soon to be disabled textbox to a hidden value so you can access the value, even though the textbox is disabled and valueless.

<!DOCTYPE html>
<html>
<body>

<form action="demo_form.asp">
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname" disabled><br>
<input type="hidden" name="lnameIfDisabled" value="Pizza">
<input type="submit" value="Submit">
</form>

</body>
</html>

Please mark the question as answered if this solves your problem. Thanks.


这篇关于如何保存和检索只读类​​型的文本框的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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