I am trying to inject a value stored in a PHP $_SESSION variable into the "value" attribute of an input tag using javascript. I am able to successfully inject the PHP code in the "value" attribute, but the stored value does not appear in the text box. My code is below:
HTML:
<input type="text" name="fname" value="" />
Javascript:
fields.eq(n).attr('value', "<?php echo $_SESSION['fname'] ; ?>");
The problem is that this would usually place the value of the $_SESSION['fname']
variable in the input box. But that is not the case. When the button is clicked to inject the PHP code into the value attribute, this is what the HTML looks like:
<input type="text" name="fname" value="<?php echo $_SESSION['fname'] ; ?>" />
And this is what I want it to look like but in the text box, it actually shows the PHP code and not the value stored in $_SESSION['fname']
.
Is there something I am missing? Shouldn't this work? Any help is appreciated!