(answers aggregated into another question)
The following jquery 1.3.2 code works:
<input type="select" value="236434" id="ixd" name='ixd' />
<script>
console.log( $('#ixd') );
console.log( $("input[name='ixd']") );
</script>
Console shows:
[input#ixd 236434]
[input#ixd 236434]
However setting the input to "hidden" prevents the selectors working. Any clues?
<input type="hidden" value="236434" id="ixd" name='ixd' />
<script>
console.log( $('#ixd') );
console.log( $("input[name='ixd']") );
</script>
Console shows:
[]
[]
There two possible way to detect the value change on the hidden input field: By using bind() method. By using change() method.
In JavaScript, you can use following two ways to get hidden field value in a form : document. getElementById('hidden field id'). value.
The <input type="hidden"> defines a hidden input field. A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted.
You can simply use the jQuery :visible or :hidden selector to select all the visible or hidden elements in an HTML page. The jQuery :visible selector considered an element visible if they consume space in the document.
Not sure why that would be failing. I do the same thing at work on a regular basis, and it works regardless of the formfield being hidden or not.
Perhaps try this:
<input type="hidden" value="236434" id="ixd" name='ixd' />
<script>
console.log($("#xid").val())
</script>
That will get you the value of the hidden field. To get the value out of a form field, the .val()
method needs to be used.
<input type="select" value="236434" id="ixd" name='ixd' />
Is that even valid markup?
It appears that selecting a visible input retrieves the value of it, even without explicity calling .val()
, whereas selecting a hidden one does not:
Try:
console.log( $('#ixd').val() );
console.log( $("input[name='ixd'][type='hidden']") );
and
console.log( $("input[name='ixd']").val() );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With