0

I get data.my_id from an AJAX call. I want to place it inside a hidden input named my_id, but I am not able to do it. Is there a special way to succeed with this sort of input? Is it normal not to see the AJAX return in the sources of the page? Thanks and sorry for my school English.

// dat.my_id is working in an alert
$(#my_id).html(data.my_id);
<input type="hidden" name="my_id" id="my_id" value="<?= $my_id; ?>" />
4
  • 1
    try $(#my_id).val(data.my_id); Commented Jul 12, 2016 at 7:41
  • you could hide your input through css, using: display:none; Commented Jul 12, 2016 at 7:51
  • @krisph you can do it olso with css but he didn't ask how to hide it, he ask how to pass the value ;) Commented Jul 12, 2016 at 8:00
  • Just a suggestion really Commented Jul 12, 2016 at 8:06

2 Answers 2

1

You need to keep value of hidden empty initially.

<input type="hidden" name="my_id" id="my_id" value="" />

Then on ajax response you can set the value as below:

$("#my_id").val(data.my_id);
Sign up to request clarification or add additional context in comments.

Comments

0

To pass a value to your input you can use

$('#my_id').val(data.my_id);

Some examples

12 Comments

Not working. nothing in the sources show me i retrieve the data.
I've change to test hidden with text and data is not there.
try passing the values manualy. On your browser open inspect element end go to console. After going to console try $('#my_id').val("test"); does the value changes?
uncaught type error my_id isn"t a function (message on console) but to test i've changed my input hidden in input text perhaps it's why. Sorry for my english
it's ok dont worry what have you typed on console?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.