4
Hello What I need is this: have a form and on it I mount inputs whose values are the data of a table I run in a loop, I assign an id to each of these imputs with the field name and the number of an autoimcrement field in that table, then I want to take the values of these input via jquery picking these values by the id of each input and for that I wanted to pass the id of each record and in jquery mount the name of the input id dynamically into a variable, something like:
function salvaCamposForm(idDaTabela){
var idInput1 = '#nomedoimput1'+idDaTabela;
var idInput2 = '#nomedoimput2'+idDaTabela;
// dai, passar isso para atribuir o valor para a variavel que
// que vai ser passada para o post
fPostInput1 = $(idInput1).val();
fPostInput2 = $(idInput2).val();
// ...
}
Can this be done in Jquery?
thanks!!!
Light and Peace!!!
How many inputs are there? or better: are all inputs within the form? what do you want to do at the end of the function, send ajax?
– Sergio
thank you friend! Next, has a form to register user with profphysiol experiences that is filled in a modal form, so far blz, but, when log in to the site, displays the full user form and within it I traverse the table experiences and assemble the inputs with the fields of this table in a div with a "Refresh Experience" button whose id is "_atliz_exp"+Idincretabela, so that when the guy clicks on one of these buttons I need to pass both the id of that button to the jquery to know which btn was clicked, and the id of the inputs in the divDess button and move to the post, as I wrote in the question.
– Armando Marques Sobrinho
I’m not sure if I understand, if you put the HTML it’s clearer... but having a
$('button').on('click', fn...
do you know which button is clicked right? your ID you can take withvar id = this.id;
and then you can use the$(this).closest('form');
to know the form or.closest('div')
to find out what button the button is on... that’s what you want?– Sergio
that is, both buttons and fields will have the same id followed by the number of the corresponding record, so I do not know the id’s neither buttons nor capos, so I need to do what I asked, i.e.: assemble the id text into a variable and take the value by this variable and pass the corresponding value to the post.
– Armando Marques Sobrinho
That is: exactly as I asked, as I do not know which boot nor which field, I need to do: var botaop = '#botaoppp"+idIncrement; var campop = '#campoxxx+idIncrement; dai fazer: $(botaop). on('click, fn... var postCampop = $(campoxxx). val(); ....
– Armando Marques Sobrinho
I don’t know if you got me right, take a look here: https://jsfiddle.net/z8pae6sx/ do you see that it is always possible to know the button and div ID? is that what you’re looking for? Join your HTML, it’s easier to understand the problem.
– Sergio
opa Rgio, it would look something like this but, in my case, I would even assign the id as in the case,
var botaop = '#id_botao'+idDaTabela;
and then$(botaop).on('click',fn...);
– Armando Marques Sobrinho
But you want to assign the ID when you click or the element already has an ID and you want to know what it is when you click?
– Sergio
that same, part of the id I know, which are fixed, the other part is the numer that has in the id field of each record, so, are several buttons, the guy clicks on one and I pass the id number of the record for Function, then I mount the variable with the fixed part of the id of fields plus the number coming in the Function parameter and pick the value using that variable that would have to be the id of the field, understood?
– Armando Marques Sobrinho
but thank you, I will see here what I do and put here the answer when finished, ok! values same guy
– Armando Marques Sobrinho