最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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>

发布评论

评论列表(0)

  1. 暂无评论