Place a value inside the jquery val

Asked

Viewed 66 times

0

What is the correct way to assemble this line?

$("#rastreo").val('BR'<?php echo date("hYmdi"); ?>json[0].estado);

Trace ID is an input field.

  • 1

    "rastreo" is what ? Can give more details. is an input, a div ?

  • This field is an input

  • What problem are you having?

  • @Marconi does not work. Prevents loading of all other js..

2 answers

3


Remember that to concatenate strings with js the '+' character is used. Then your original code would be:

$("#rastreo").val('BR'+<?php echo date("hYmdi"); ?>+json[0].estado);

An alternative way may be:

$('#rastreo').attr('value', 'BR'+<?php echo date("hYmdi"); ?>+json[0].estado);
  • Maybe this is his mistake.

  • It worked, thank you :)

0

If it is a input you must do this way:

$("#rastreo").val('TESTE');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id ="rastreo"> </input>

In this case it is the same way you are doing today. So I believe the problem lies in :

<?php echo date("hYmdi"); ?>json[0].estado
  • I am aware. My doubt is how to do it the right way in the way I need above.

  • You should detail your question better. Inform what the return of json[0].estado for example. And also what error is occurring, so we can help you;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.