I am creating a checkbox in HTML like this:
<input type="checkbox" name="vehicle" value="Bike" /> I have a bike<br />
Now, I want I have a bike part i.e. the text that comes besides a checkbox to come from a variable. How can this be done?
<input type="checkbox" name="vehicle" value="Bike" id="vehicle" />
<label for="vehicle" id="lblVehicle"></label><br />
<script>
var lblBike = 'I have a bike';
document.getElementById('lblVehicle').innerHTML = lblBike;
</script>
var yourTextVariable = 'I have a cool bike';
document.getElementById('vehicle').innerHTML = yourTextVariable;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With