Quote:
<input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input>
<input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input>
<input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input>
<input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input>
First of all, all the
TextBox Id
are same, which can't be possible.
Id
is a attribute which should be different from all other elements on the page.
So, if you change the code to...
<input id="ChildidIntl1" class="onlyforage" type="text" name="ageperwise[1]"></input>
<input id="ChildidIntl2" class="onlyforage" type="text" name="ageperwise[1]"></input>
<input id="ChildidIntl3" class="onlyforage" type="text" name="ageperwise[1]"></input>
<input id="ChildidIntl4" class="onlyforage" type="text" name="ageperwise[1]"></input>
Then getting the value is easy in
jQuery.
Value by Selecting IDs
It is like
$('#ChildidIntl1').val();
.
Demo -
[Demo] Value from TextBoxes on Button Click[
^]
Value by Selecting name
If you want to use "
name
" attribute to get the value, then you have to select each of the
TextBox
with the help of
Attribute Equals Selector [name="value"][
^].
So, code would look like...
var allValues = "";
$('input[name="ageperwise[1]"]').each(function(){
allValues += $(this).val() + "\n";
});
Demo -
[Demo] Value from TextBoxes (having same name) on Button Click[
^]
Value by Selecting class
As per
Karthik's comment, I am also giving the Demo of selecting the value by class name.
Demo -
[Demo] Value from TextBoxes (having same class) on Button Click[
^]