3
I am trying to read a field in a table that is of the whole type. And it is also a primary key and auto-increment.
The value returned is put in a label (I’ve tried putting in an input text as well).
To read the target table and put the result on the label, I use a Jquery statement. The event is a click on
<input type='file':
The click code is
jQuery("#idFilFoto").click(function (){
var nSigla=jQuery("#idLblSigla").text();
var tabela = "TabPessoas";
var clausulaWhere = " TabPessoasSigla = '"+nSigla+"'";
var jqxhr = $.post("genericaPegaID.php",{tabela:tabela,clausulaWhere:clausulaWhere}, function(resultado) {
jQuery("#idLblID").text(resultado);
});//fim do post
});//fim do click
This works well.
On the label
<label id="idLblID"
value is set correctly. An integer with no spaces before or after.
Now, I want this value inside that label to use it in another table.
The completion of this table is done by the event click of a button.
jQuery("#idBtnSalvar").click(function (){
var tabela="TabFotos";
var campos="TabFotosCaminhoArquivo,TabFotosFKPessoas";
var matricula = jQuery("#idLblID").text();
var foto = jQuery("#idFilFoto").val();
var posicao = foto.indexOf("fakepath");
foto = foto.substr(posicao+9);
var valores="'"+foto+"',"+matricula;
alert (tabela+" : "+campos+" : "+valores);
/*
var jqxhr = $.post("genericaInserir.php",{tabela:tabela,campos:campos,valores:valores}, function(resultado) {
alert("success "+resultado);
});//fim do post
*/
});//fim do botao salvar
The block commented above is because the 'values' field forces an error in the Insert Into statement I have on the generic page Insert.php. It says that the value of the 'matricula' field is non-numerical.
Really, if you inspect what was going to the 'post' (see Alert before the commented block) appears, for example, like this:
'photo.png',[][]6.
Please interpret the two brackets as two closed symbols, like two rectangles.
It should be just the number 6, in case.
I tried to
var matricula = parseInt(jQuery("#idLblID").text(),10);
but the result is Nan in Alert.
Thank you very much. It worked perfectly with the 'Trim' method'.
– user4701