Reputation: 899
i want to get the value of textbox on the basis of its class and id. this what i have done but it is not working for me. although i can set the value of textbox by doing this.Please help me out
<script>
....
var count=1;
var check=$(".AssVal,#"+count).val();
....
<script>
<input type="text" value="0" class="AssVal" id="1" maxlength="20" size="20" />
This is how i set the value in textbox
var check=$(".AssVal,#"+count).val(123);
Upvotes: 2
Views: 6693
Reputation: 15387
You can set the value using class as below
$(".AssVal").val("123");
By ID as
$("#1").val("123");
For getting
alert($("#1").val());
alert($(".AssVal").val());
And for dynamic
alert($("#"+count).val());
Upvotes: 0
Reputation: 1964
Using jQuery, you can get the value simply by not passing any arguments to the val()
function you've already used. This would look like:
var myValue = $(".AssVal,#"+count).val();
Upvotes: 0
Reputation: 9947
use class selector . is used for selecting classes and # for ID
var testvalue = $(".AssVal").val()
or
var testvalue = $("#1").val() // try not using no's as id
Upvotes: 0
Reputation: 78595
Since an ID attribute is unique, you can just use the ID on it's own:
// Get value
var check=$("#"+count).val();
// Set value
$("#"+count).val(123);
But the problem with your selector is that jQuery is trying to find all .AssVal
elements and all elements with id=1
as a comma in a selector denotes attempting to join multiple selectors.
Upvotes: 2