When I define the value of a submit button in HTML, I can cause a line break:
<script>
function change_value() {
if (document.getElementById('click_me').checked) {
document.getElementById('next').value='Next';
} else {
document.getElementById('next').value='Text with line break';
}
}
</script>
<form>
<input id="click_me" type="checkbox" name="click_this" value="1" onclick="change_value()">
<input id="next" type="submit" value="Text with line break">
</form>
Before clicking the checkbox, the submit button looks like this:
But when I set that value using JavaScript, the line breaks are being displayed as text:
How can I insert a text with line break using JavaScript?
Note.
This only needs to work in recent versions of Firefox.
In js the line break character is \n
, that should be used when you set the value property
function change_value() {
if (document.getElementById('click_me').checked) {
document.getElementById('next').value = 'Next';
} else {
document.getElementById('next').value = 'Text with\nline break';
}
}
<input id="click_me" type="checkbox" name="click_this" value="1" onclick="change_value()">
<input id="next" type="submit" value="Text with line break">