-3

I have multiple text boxes which are created dynamically , these text boxes have the same name different id's. I need to get values of all those text boxes via ajax but did not have any clue, please suggest how can I achieve this.

Edit

I had tried

$('#addMultipleEducationLevel').on('click', function () {
    $.ajax({
        url: "${createLink(controller: 'someController', action: 'someAction')}",
        data: {degreeId:$( "#degree" ).val(),fieldOfStudy:$('[name=fieldsOfStudy]').serialize()}
    });
})

But I am getting

 [fieldOfStudy:fieldsOfStudy=&fieldsOfStudy=Biblical+Hebrew&fieldsOfStudy=Applied+Business+(Double+Award), degreeId:3, action:someAction, controller:somecontroller]
ABC
  • 4,263
  • 10
  • 45
  • 72

4 Answers4

1

You can simply use an attribute selector and serialize() to gather the data to send:

var ajaxData= $('[name=name]').serialize();

$.post('/path/to/server', ajaxData, function(response){
   /* do something with response */
});

DEMO

charlietfl
  • 170,828
  • 13
  • 121
  • 150
  • 1
    check it for what? You need to be more specific with your issue details as to what your expectations are. That is why you are getting numerous down votes – charlietfl Jul 05 '14 at 13:17
1

hi @Abdullah you get all value using this way.

if you have multiple textbox with same name like

<input type="text" name="a1" value="a">
<input type="text"  name="a1" value="b">
<input type="text"  name="a1" value="c">
<input type="text" name="a1" value="d">

jquery code:

var a="";
$("input:text").each(function () {
    if (this.value != undefined) {
        a += this.value +',';
    }       
});
alert(a);

and now submit your value with ajax

$.ajax({
    url: "send.aspx?value=" + a,
    type: "get"
}).done(function () {
    alert("Send successfully!!");
});

Live demo

NorCode
  • 679
  • 1
  • 12
  • 33
0

Try this way

Script is

$(document).ready(function () {
    $('#ex input:text').each(function(){
       alert(this.value) 
    });
});

Example HTML

<div id="ex">
    <input type="text" id="one" name="first" value="10">
    <input type="text" id="two" name="first" value="11">
    <input type="text" id="three" name="first" value="12">
</div>

DEMO

Sridhar R
  • 20,190
  • 6
  • 38
  • 35
0

To get a textbox value, according to the fact that they have different IDs try the following jQuery snippet:

$("#ID OF YOUR CHECKBOX").val();

Then if you want to send these values via AJAX, use this snippet:

$.ajax({
    url: "receiver.php?value="+your_value_here+"&value2="+anpther_value_here,
}).done(function() {
    alert("data sent");
});
Valentin Mercier
  • 5,256
  • 3
  • 26
  • 50