Reputation: 37
I have a textbox in HTML that I need to set its value. Upon loading the modal (twitterbootstrap) the textbox should have its predefined value.
I'm having trouble in outputting the value from php.
I have this code:
<input class="form-control" type="text"
name="inputBirthdate" id="datepicker"
value=<?php echo $displayBdate; ?> required>
</div>
</div>
<script src="pikaday.js"></script>
<script>
var picker = new Pikaday(
{
field: document.getElementById('datepicker'),
firstDay: 1,
minDate: new Date('1980-01-01'),
maxDate: new Date('2020-12-31'),
yearRange: [1980,2020]
});
</script>
The variable $displayBdate
has the value string: "Sat Oct 18 2014". When I try checking the value of that variable by using the die($displayBdate)
, it outputs exactly as "Sat Oct 18 2014".
Now, what I'm getting really is only "Sat". Also, when I try value=<?php echo 'WAT DA F'; ?>
the textbox has only "WAT". It means the error starts from the first space. help
Upvotes: 1
Views: 150
Reputation: 5643
You need to wrap the PHP value inside quotation marks.
Change this...
<input class="form-control" type="text"
name="inputBirthdate" id="datepicker"
value=<?php echo $displayBdate; ?> required>
...into this...
<input class="form-control" type="text"
name="inputBirthdate" id="datepicker"
value="<?php echo $displayBdate; ?>" required>
Upvotes: 2