Reputation: 7953
i have a text box and i try to get value like this
var comment = $("input#diaMissedPucomments").val();
but the value is not fetched at the same time i have used this
$('input:checked').each(function() {
selectedValues =$(this).val()+","+selectedValues ;
});
to get values of selected check boxes it works fine.
<div style="display:none;" id="diaMissedPU" title="Missed P/U Comments" >
<table>
<tr>
<td>Enter Comments : </td>
<td><input tyep="text" id="diaMissedPucomments" name="diaMissedPucomments" /></td>
</tr>
</table>
</div>
the above is the HTML and i want to get the value of diaMissedPucomments
how to do this.
Pleas help me to get this.
Best Regards
Upvotes: 0
Views: 290
Reputation: 19327
It's just a mistyped tyep
and must be fixed to type
<input tyep="text" id="diaMissedPucomments" name="diaMissedPucomments" />
must be
<input type="text" id="diaMissedPucomments" name="diaMissedPucomments" />
DEMO: http://jsfiddle.net/vnKza/1/
As dakait says enclose your Jquery codes to a Jquery ready handler
$(function(){
var comment = $("input#diaMissedPucomments").val();
//your other codes
});
Upvotes: 5
Reputation: 36531
i see you have spelled your input type wrong..
tyep="text" //here
should be
<input type="text" id="diaMissedPucomments" name="diaMissedPucomments" />
and jquery seems fine..
UPDATED
$(document).ready(function(){ //make sure you have the javascript codes inside document.ready
var comment = $("#diaMissedPucomments").val();
});
Upvotes: 3
Reputation: 2620
like everybody has mentioned that you have a typo, plus make sure you have wrapped the code inside the ready handler
$(function(){
//your code here
});
why it work on jsfiddle then? because with default setting the fiddle wraps the code in document ready
Upvotes: 2