I need to update the value of some input fields of a form, using values from a second (dynamically generated) div.
Here’s the code
$("#second_update_form_data :input").each(function(index) {
//find all input fields in the second div
var FieldName = $(this).attr("name");
var FieldValue = $(this).val();
//try to get the corresponding field from the original form to change it
var Selector = "#TT_CartForm__form input[name=" + FieldName + "]";
var OriginalFiled = $(Selector);
This does not work, but I’m not sure why. I could add an id to the original input fields and use that to select them, but I’d prefer to understand what’s wrong and use the correct selector.
Thanks in advance, kind regards
EDIT: I’m sorry, I realize I didn’t specified which part doesn’t work. It is the last line, when I try to select using Selector, so it’s this last one that seems to be wrong
To get all input fields inside div with JavaScript, we select the container div with querySelector . Then we select all the input elements inside with querySelectorAll . to add inputs inside the div. to select the div with querySelector .
You can't place any element inside an input. An input does not contain any HTML. Show activity on this post. The way to do that is to put the input and the wanted div inside a wrapper div, which should look like the input - the wanted width, length of the input and should have border.
Element Selectors The selector "input[type=text]" means select all inputs with the type attribute equal to text.
Use document.querySelector on to select a div and then select an element within it with the given class after that. We just call querySelector on the element with the ID mydiv to select items inside that div. Therefore, innerDiv is the div with the class myclass .
UPdated based on your update
var OriginalFiled = $('#TT_CartForm__form input[name="' + FieldName + '"]');
Try changing your quotations around to ensure string vaiable read. something else to keep in mind, IE7 and IE8 support attribute selectors only if a !DOCTYPE is specified. and in IE6- they dont work ata all
Also double check your element ID name, I notice it has two areas that are underscore and one area has 2 underscores. Make sure the div holding your input has that exact same id value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With