Neliswa Astute Neliswa Astute -4 years ago 85
HTML Question

php code is not parsing properly in HTML input tag

I have scrpit that reads from the database.And it displays properly in the other textboxes, except for one textbox which is supposed to display the value of a students test 1.
the logic is->if the value is >0 then that text box must be disabled.

Here is the code that does not display properly on the text box. What Am I missing?

<td>Test 1</td>
<td><input class="form-control" disabled placeholder="Enter Test 1" id="test1" name="test_1" type="text" value="
<?php
echo $test1;
if($test1>0){
?>
<script>
document.getElementById("test1").disabled = true;
</script>
<?php
}
?>"/>
</td>

Answer Source

Simple solution is:

<td>
    <input 
        class="form-control" 
        placeholder="Enter Test 1" 
        id="test1" 
        name="test_1" 
        type="text" 
        value="<?php echo $test1;?>" 
        <?php if ($test1 > 0) echo ' disabled';?>
    >
</td>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download