4

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?

1
  • 7
    From what kind of variable? Server-side? Client-side? Commented Aug 1, 2012 at 6:37

2 Answers 2

7
<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>
Sign up to request clarification or add additional context in comments.

Comments

2
var yourTextVariable = 'I have a cool bike';
document.getElementById('vehicle').innerHTML = yourTextVariable;

1 Comment

@Sam actually question was tagged with html so i thought it would be JavaScript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.