0

I have a form button and I want 2 lines of text. In the form I have this

value='".$row['item'].'
$'.$row['price']."'

and I get

Hot Dog
$1.00

I want to update this in JavaScript and tried this

sBtn = itm + "
$" + prc;
document.getElementById(conbtn).value = sBtn;

and

sBtn = itm + "<br>$" + prc;
document.getElementById(conbtn).value = sBtn;

without success. The first gives

Hot Dog&#10;$1.00

and the second

Hot Dog<br>$1.00

Any idea how to write 2 lines from JS?

3
  • try using innerHtml instead of value Commented Dec 31, 2012 at 2:46
  • What is conbtn? Is it <input type='button'>? Commented Dec 31, 2012 at 2:48
  • Set the innerHTML property of the conbtn element to sBtn instead of its value property to sBtn. Commented Dec 31, 2012 at 2:49

2 Answers 2

1

I got it. Used

sBtn = itm + "\r\n$" + prc;
Sign up to request clarification or add additional context in comments.

Comments

1

If you have a form input button, use an escaped newline in the value property.

document.getElementById(conbtn).value = "Test 1\nTest 2";

If you have a button tag element, use a break element in the innerHTML property.

document.getElementById(conbtn).innerHTML = "Test 1<br/>Test 2";

Comments

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.