admin管理员组

文章数量:1328037

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>

本文标签: javascriptGetting Value from disabled attribute in htmlStack Overflow