Click to See Complete Forum and Search --> : embed <br> in alert msg box


GreyArea
06-05-2003, 11:05 AM
Hello all,

I'm building a string variable then passing it to an alert(). Basically I'm doing form validation and appending a string for each required field that is not entered. Then I'd like to display each string message as a separate line in an alert. My br tags are getting displayed instead of rendering to a new line. What am I missing here ??:confused:

TIA,

Aaron

Khalid Ali
06-05-2003, 11:10 AM
<br/>
is an html tag and the code in alert() is javascript.

to see a line break use \n

new line flag for javascript.

GreyArea
06-05-2003, 12:09 PM
Khalid,

Thanks !! I could've swore I tried that, but obviously not cause it worked. I tried so many different variations I lost track, must have used the chr(10)chr(13) syntax.

Thanks again,

Aaron

Khalid Ali
06-05-2003, 12:17 PM
You are welcome..:D

Charles
06-05-2003, 12:24 PM
JavaScript doesn't have a chr function. You have to use \OOO where "OOO" is a one to three didget, octal number, '\xHH' where "HH" is a two didget, hexidecimal number or \uUUUU where "UUUU" is a four didget hexadecimal number.

<script type="text/javascript">
<!--
alert(['fee', 'fie', 'foe', 'fum'].join('\x0a\x0d'));
// -->
</script>

But do not use that; it's OS dependant. It'll work on a DOS based system, but other systems use different end of line characters. That's why we have '\n'.