Display var on input field without using the value attribute
<p>I have a PHP variable which I am trying to get to appear onto an input field without using the 'value' attribute but I can't seem to get that to work. </p>

<p>I tried a jQuery code I found first to 'append' the variable to the input field but that didn't work.</p>

<pre><code>    var first_name = "&lt;?php echo $current_user['first_name']; ?&gt;";
    alert(first_name);
    $('#first_name').val($('#first_name').val() + first_name);
</code></pre>

<p>I then tried using getElementById but it also didn't work. </p>

<pre><code>    var first_name = "&lt;?php echo $current_user['first_name']; ?&gt;";
    alert(first_name);
    document.getElementById('first_name').value = first_name;
</code></pre>

<p>Any suggestions would be greatly appreciated!</p>

<p>EDIT:</p>

<p>This is the HTML form</p>

<pre><code>&lt;form name="personal_form" action="includes/editpersonal.php" method="POST"&gt;
   &lt;fieldset&gt;
      &lt;legend&gt;&lt;h2&gt;Personal Details&lt;/h2&gt;&lt;/legend&gt;
      &lt;table class="personalform"&gt;
         &lt;!--if there is an error on first name, the class name 'form_error_row' will be input into the following tr--&gt;
         &lt;!--allows me to colourise the text field to indicate an error on this row--&gt;
         &lt;tr class="&lt;?php echo form_row_class("first_name") ?&gt;" &gt;
            &lt;th&gt;&lt;label for="first_name"&gt;&lt;p&gt;First Name: &lt;/p&gt;&lt;/label&gt;&lt;/th&gt;
            &lt;td&gt;
            &lt;input type="text" name="first_name" id="first_name" size="40" /&gt;
            &lt;!--if there is an error it will print out a div with the error message--&gt;
            &lt;?php echo error_for('first_name') ?&gt;
            &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;  
   &lt;/fieldset&gt;
   &lt;input type="submit" class="reg-button" value="Update Records" /&gt;
&lt;/form&gt;
</code></pre>
