1
I have a JS function that calls an ajax and passes the parameters (codigo, id_trigger, info1,..., info10)
and passing info1 = document.getElementById('textTicker').value
he turns into a string, if I give console.log(info1)
it returns me the text itself: "Document.getElementById('textTicker'). value" and not really the field value.
Is there any way I can get that value from the field?
info1 = "document.getElementById('textTicker').value";
function CallAjaxGenerico(codigo, id_trigger, info1, info2, info3, info4, info5, info6, info7, info8, info9, info10){
$('#'+id_trigger).change(function(){
$.ajax({
...
data : {
'CODIGO' : codigo,
'INFO1' : document.getElementById(''+id_trigger+'').value,
'INFO2' : info1
}
});
}
and the console.log(info1) returns "Document.getElementById('textTicker'). value"
You’d have to show the code because it shouldn’t happen in normal situations.
– Sam
do not quote, or you will see a string.
– Sam
I’m using a php function that calls this function from the js file. In this js Document.Elementbyid file comes as string
– Daniela T.
Okay, but that way the value of
info1
will always be the stringdocument.getElementById('textTicker').value
and not the value of#textTicker
.... Javascript does not execute commands and methods inside quotes... everything inside quotes is string for JS– Sam
tried using $("#textTicker"). val() or $("#textTicker"). text() ??
– M. Bertolazo
Do not put code referring to the question in comments. Instead, edit the question and put the code there, formatting it with
Ctrl + k
or with the button{}
of the editor– Isac
@Danielat. you’ll have to wear one
eval()
In this string, it is something very funny but it is what you do if you need to execute JS code from a text: https://jsfiddle.net/tbyqy4Lz/ - Docs.– Renan Gomes
@Renan using Eval() worked! Thank you so much!
– Daniela T.
Do not use Val, I doubt very much that justifies your case. Why not use the Jquery selectors and take the value with
val()
. By the way you use this method$('#'+id_trigger).change(function(){
and then passes a string? Review its implementation. Not critical is advice.– lazyFox