Input value doesn't display. How is that possible?

后端 未结 13 2101
后悔当初
后悔当初 2021-02-04 23:54

This must be something utterly stupid that I\'ve done or am doing, but I have an input with a value attribute that simply isn\'t being displayed:

相关标签:
13条回答
  • 2021-02-05 00:20

    For Googler's who may have the same issue: This can happen if you have a non-numeric value in a number type input field.

    For example:

    <input type="number" value="<? echo $myNumberValue; ?> "/>
    

    This will show nothing even though Dev tools says the value is there, since the extra space after ?> makes it non-numeric. Simply remove the extra space.

    0 讨论(0)
  • 2021-02-05 00:20

    For me it was because I was using the <input> tag without enclosing it inside a <form> tag

    0 讨论(0)
  • 2021-02-05 00:20

    Same problem occured on electron:

    I was clearing the field with document.getElementById('_name').value = '' instead of document.getElementById('_name').setAttribute('value', "").

    So I guess simple quote broke the field or input has a second value hidden attribute because I could rewrite on the fields and it won't change the value on the inspector

    0 讨论(0)
  • 2021-02-05 00:22

    Argh. I knew this was going to be something beyond stupid. There was a bit of Javascript that was clearing data. The clearing was useful in other places, but I didn't know it was executing so it was a serious pain to track down. Once I prevented the clearing in this scenario, my values actually appeared. Because I was looking at the code in web inspector, I assumed that it would be a "live" view, but I guess that's not entirely true.

    Thanks for your help, everyone.

    0 讨论(0)
  • 2021-02-05 00:24

    For me the problem was that I had multiple inputs with the same id. I could see the value in the field, but reading it via javascript gave an empty value because it was reading a different input with the same id - I was surprised that there was no javascript error, just could not read the values I could see in the form.

    0 讨论(0)
  • 2021-02-05 00:26

    Mine was related to AngularJS

    I was trying to put both an HTML Value and an ng-Model, thinking that the ng-Model would default to the Value, because I was too lazy to add the Model to the $scope in the Controller...

    So the answer was to assign that default value to the $scope.variable in the controller.

    0 讨论(0)
提交回复
热议问题