Jason Templeman
Jason Templeman

Reputation: 488

forms and javascript

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?

Upvotes: 0

Views: 90

Answers (2)

Ryan Stein
Ryan Stein

Reputation: 8000

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";

Upvotes: 1

Jason Templeman
Jason Templeman

Reputation: 488

I got it. Used

sBtn = itm + "\r\n$" + prc;

Upvotes: 1

Related Questions