spewn
Programmer
- May 7, 2001
- 1,034
dang...this is funny...i have been trying to get this code to work:
****
<html>
<head>
<title>Line Breaks Part II</title>
<script language="javascript" type="text/javascript">
function addbr() {
txt = '';
mytext = document.getElementById('mytext');
val = mytext.value;
if (val!='') {
val2 = val.split("\n"
val3 = val2.length;
if (val.indexOf('\n')!=-1) {
document.getElementById('submit').disabled = true;
for (s=0; s<val3; s++) {
brk = '<br>';
ln = '\n';
if (s==0) {txt = '';}
if (!val2
}
mytext.value = txt;
}
}
mytext.focus();
}
</script>
</head>
<body>
<form name="myform" action="javascript:addbr();">
<textarea name="mytext" cols="50" rows="8"></textarea>
<br>
<input name="submit" type="submit" value="Submit">
</form>
</body>
</html>
****
for some reason it carries the carriage return with each element in array val2...i have tested for the presence of \n in each array item, but it returns false. yet one exists in the output, or so it seems. there is purposely a \n after the <br>, but not after the val2 array item, although it line breaks anyway...i can't it to work, so i give it to the group.
if input looks like this:
line 1
line 2
line 3
output should look like this:
line 1<br>
line 2<br>
line 3<br>
any ideas?
- g