javascript - Getting Value from disabled attribute in html - Stack Overflow

I had a form which can edit some parameters and some are disabled.While uploading the edited form the d

I had a form which can edit some parameters and some are disabled.While uploading the edited form the disabled parameters returned null value,my code is as follows,

<div class="form-group col-md-6">
      <label class="control-label required"  for="name">Name</label>
      <input type="text" readonly="readonly" disabled value="{user.name}}">
</div> 

So while submitting the form ,should uses value "user.name" but it returns null since I provide disabled attribute.

I had a form which can edit some parameters and some are disabled.While uploading the edited form the disabled parameters returned null value,my code is as follows,

<div class="form-group col-md-6">
      <label class="control-label required"  for="name">Name</label>
      <input type="text" readonly="readonly" disabled value="{user.name}}">
</div> 

So while submitting the form ,should uses value "user.name" but it returns null since I provide disabled attribute.

Share Improve this question asked Aug 23, 2018 at 6:13 A.JRJA.JRJ 3711 gold badge6 silver badges17 bronze badges 3
  • If you mark it as disabled then it won't pass along its value. Perhaps you can mark it as readonly if that fits your requirement? – Mohit Bhardwaj Commented Aug 23, 2018 at 6:19
  • @MohitBhardwaj Using readonly make the parameter similar to other where editing cursor is there but cant'edit.but my requirement is it should be look like disabled but it should pass its value – A.JRJ Commented Aug 23, 2018 at 6:24
  • 1 how about using js to enable them just before sending ? you should be able to do it overiding form.onsubmit – jonatjano Commented Aug 23, 2018 at 6:27
Add a ment  | 

2 Answers 2

Reset to default 5

Use only readonly instead of disabled

There is 2 choices :

<input type="text" value="{{user.name}}" readonly>
// In this case you can get post values  

<input type="text" value="{{user.name}}" disabled>
// In this case you can not get post values  

my requirement is it should be look like disabled but it should pass its value

You can use CSS to make it look disabled

.disabled {
  background: #ccc;
  cursor: not-allowed;
  border-width: 1px;
}
<input type="text" readonly="readonly" class="disabled" />
<input type="password" readonly="readonly" class="disabled" />
<textarea readonly="readonly" class="disabled"></textarea>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742242598a4407317.html

相关推荐

  • javascript - Getting Value from disabled attribute in html - Stack Overflow

    I had a form which can edit some parameters and some are disabled.While uploading the edited form the d

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信