Jeff Lee
Jeff Lee

Reputation: 11

Can't I set a variable as a textbox value

$value = 3;
<input type="number" name="rowid" value=$value readOnly><br>

I tried setting a variable as textbox value, however,it won't work. Is it impossible to set a variable as a textbox value?

Upvotes: 0

Views: 62

Answers (3)

Sulthan Allaudeen
Sulthan Allaudeen

Reputation: 11310

You're just placing the value $value there. It doesn't have any sense to have $value without opening php tag there.

You need to echo the $value to have assign on rowid.

You should do

<input type="number" name="rowid" value="<?= $value ?>" readOnly><br>

or

<input type="number" name="rowid" value="<?php echo $value ?>" readOnly><br>

Additional Tip :

You can do the debug yourself by seeing the Page's source (view-source://yourpagename.php) or by Inspecting the area where you starring in from the Browser

Upvotes: 1

Nana Partykar
Nana Partykar

Reputation: 10548

echo $value inside value=""

$value = 3;
<input type="number" name="rowid" value="<?php echo $value;?>" readOnly><br>

OR

<input type="number" name="rowid" value="<?= $value;?>" readOnly><br>

Upvotes: 1

Pierre
Pierre

Reputation: 1583

You need to echo the variable

<input type="number" name="rowid" value="<?php echo $value; ?>" readOnly><br>

Upvotes: 1

Related Questions