jQuery find all input type with select for ajax request
I am trying to perform an ajax request by setting FormData using jquery each loop after finding input and select element for update as follows:
$(document).on("click", ".update", function (e) {
e.preventDefault();
e.stopPropagation();
let thisBtn = $(this);
//Form Data
let formData = new FormData();
let thisRow = thisBtn.closest("tr");
thisRow.find("input,select").each(function() {
//console.log(this.value)
formData.append($(this).attr('name'), $(this).val());
});
$.ajax({
type: "POST",
url: '<?php echo base_url()?>exam/update',
data: formData,
processData: false,
contentType: false,
success:function(data){
if($.trim(data)=='yes')
{
alert('Success! Record updated successfully');
}
else
{
alert('Error! Record not updated successfully')
}
}
});
});
But getting some undefined params as follows:
But I want pure parameters except undefined
javascript jquery ajax
add a comment |
I am trying to perform an ajax request by setting FormData using jquery each loop after finding input and select element for update as follows:
$(document).on("click", ".update", function (e) {
e.preventDefault();
e.stopPropagation();
let thisBtn = $(this);
//Form Data
let formData = new FormData();
let thisRow = thisBtn.closest("tr");
thisRow.find("input,select").each(function() {
//console.log(this.value)
formData.append($(this).attr('name'), $(this).val());
});
$.ajax({
type: "POST",
url: '<?php echo base_url()?>exam/update',
data: formData,
processData: false,
contentType: false,
success:function(data){
if($.trim(data)=='yes')
{
alert('Success! Record updated successfully');
}
else
{
alert('Error! Record not updated successfully')
}
}
});
});
But getting some undefined params as follows:
But I want pure parameters except undefined
javascript jquery ajax
add a comment |
I am trying to perform an ajax request by setting FormData using jquery each loop after finding input and select element for update as follows:
$(document).on("click", ".update", function (e) {
e.preventDefault();
e.stopPropagation();
let thisBtn = $(this);
//Form Data
let formData = new FormData();
let thisRow = thisBtn.closest("tr");
thisRow.find("input,select").each(function() {
//console.log(this.value)
formData.append($(this).attr('name'), $(this).val());
});
$.ajax({
type: "POST",
url: '<?php echo base_url()?>exam/update',
data: formData,
processData: false,
contentType: false,
success:function(data){
if($.trim(data)=='yes')
{
alert('Success! Record updated successfully');
}
else
{
alert('Error! Record not updated successfully')
}
}
});
});
But getting some undefined params as follows:
But I want pure parameters except undefined
javascript jquery ajax
I am trying to perform an ajax request by setting FormData using jquery each loop after finding input and select element for update as follows:
$(document).on("click", ".update", function (e) {
e.preventDefault();
e.stopPropagation();
let thisBtn = $(this);
//Form Data
let formData = new FormData();
let thisRow = thisBtn.closest("tr");
thisRow.find("input,select").each(function() {
//console.log(this.value)
formData.append($(this).attr('name'), $(this).val());
});
$.ajax({
type: "POST",
url: '<?php echo base_url()?>exam/update',
data: formData,
processData: false,
contentType: false,
success:function(data){
if($.trim(data)=='yes')
{
alert('Success! Record updated successfully');
}
else
{
alert('Error! Record not updated successfully')
}
}
});
});
But getting some undefined params as follows:
But I want pure parameters except undefined
javascript jquery ajax
javascript jquery ajax
edited Nov 13 at 8:08
asked Nov 12 at 9:00
Bablu Ahmed
972720
972720
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Without seeing your HTML we can't tell you exactly why, but from the output it's clear that you have some input
and/or select
elements in your form which have no name
or value
. They're probably hidden, so check the DOM inspector to find and remove them.
If you don't want to amend the HTML, then you can use an attribute selector to only find the input
and select
elements which have a name
, like this:
let $thisBtn = $(this);
let formData = new FormData();
let $thisRow = $thisBtn.closest("tr");
$thisRow.find("input[name], select[name]").each(function() {
formData.append(this.name, $(this).val());
});
add a comment |
It seems that this piece of code is finding inputs/select which name attribute is undefined, what would explain the fact you are getting undefined values in the formData.
thisRow.find("input,select").each(function() {
//alert(this.value)
formData.append($(this).attr('name'), $(this).val());
});
I would recommend you to check whether the name is undefined before adding to the formData.
thisRow.find("input,select").each(function() {
//alert(this.value)
if($(this).attr('name'))
{
formData.append($(this).attr('name'), $(this).val());
}
});
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258761%2fjquery-find-all-input-type-with-select-for-ajax-request%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Without seeing your HTML we can't tell you exactly why, but from the output it's clear that you have some input
and/or select
elements in your form which have no name
or value
. They're probably hidden, so check the DOM inspector to find and remove them.
If you don't want to amend the HTML, then you can use an attribute selector to only find the input
and select
elements which have a name
, like this:
let $thisBtn = $(this);
let formData = new FormData();
let $thisRow = $thisBtn.closest("tr");
$thisRow.find("input[name], select[name]").each(function() {
formData.append(this.name, $(this).val());
});
add a comment |
Without seeing your HTML we can't tell you exactly why, but from the output it's clear that you have some input
and/or select
elements in your form which have no name
or value
. They're probably hidden, so check the DOM inspector to find and remove them.
If you don't want to amend the HTML, then you can use an attribute selector to only find the input
and select
elements which have a name
, like this:
let $thisBtn = $(this);
let formData = new FormData();
let $thisRow = $thisBtn.closest("tr");
$thisRow.find("input[name], select[name]").each(function() {
formData.append(this.name, $(this).val());
});
add a comment |
Without seeing your HTML we can't tell you exactly why, but from the output it's clear that you have some input
and/or select
elements in your form which have no name
or value
. They're probably hidden, so check the DOM inspector to find and remove them.
If you don't want to amend the HTML, then you can use an attribute selector to only find the input
and select
elements which have a name
, like this:
let $thisBtn = $(this);
let formData = new FormData();
let $thisRow = $thisBtn.closest("tr");
$thisRow.find("input[name], select[name]").each(function() {
formData.append(this.name, $(this).val());
});
Without seeing your HTML we can't tell you exactly why, but from the output it's clear that you have some input
and/or select
elements in your form which have no name
or value
. They're probably hidden, so check the DOM inspector to find and remove them.
If you don't want to amend the HTML, then you can use an attribute selector to only find the input
and select
elements which have a name
, like this:
let $thisBtn = $(this);
let formData = new FormData();
let $thisRow = $thisBtn.closest("tr");
$thisRow.find("input[name], select[name]").each(function() {
formData.append(this.name, $(this).val());
});
edited Nov 12 at 11:28
answered Nov 12 at 9:09
Rory McCrossan
241k29206245
241k29206245
add a comment |
add a comment |
It seems that this piece of code is finding inputs/select which name attribute is undefined, what would explain the fact you are getting undefined values in the formData.
thisRow.find("input,select").each(function() {
//alert(this.value)
formData.append($(this).attr('name'), $(this).val());
});
I would recommend you to check whether the name is undefined before adding to the formData.
thisRow.find("input,select").each(function() {
//alert(this.value)
if($(this).attr('name'))
{
formData.append($(this).attr('name'), $(this).val());
}
});
add a comment |
It seems that this piece of code is finding inputs/select which name attribute is undefined, what would explain the fact you are getting undefined values in the formData.
thisRow.find("input,select").each(function() {
//alert(this.value)
formData.append($(this).attr('name'), $(this).val());
});
I would recommend you to check whether the name is undefined before adding to the formData.
thisRow.find("input,select").each(function() {
//alert(this.value)
if($(this).attr('name'))
{
formData.append($(this).attr('name'), $(this).val());
}
});
add a comment |
It seems that this piece of code is finding inputs/select which name attribute is undefined, what would explain the fact you are getting undefined values in the formData.
thisRow.find("input,select").each(function() {
//alert(this.value)
formData.append($(this).attr('name'), $(this).val());
});
I would recommend you to check whether the name is undefined before adding to the formData.
thisRow.find("input,select").each(function() {
//alert(this.value)
if($(this).attr('name'))
{
formData.append($(this).attr('name'), $(this).val());
}
});
It seems that this piece of code is finding inputs/select which name attribute is undefined, what would explain the fact you are getting undefined values in the formData.
thisRow.find("input,select").each(function() {
//alert(this.value)
formData.append($(this).attr('name'), $(this).val());
});
I would recommend you to check whether the name is undefined before adding to the formData.
thisRow.find("input,select").each(function() {
//alert(this.value)
if($(this).attr('name'))
{
formData.append($(this).attr('name'), $(this).val());
}
});
answered Nov 12 at 9:05
Gabitu
1414
1414
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53258761%2fjquery-find-all-input-type-with-select-for-ajax-request%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown