Reputation: 1451
<script language="javascript" type="text/javascript">
function TextDefine(val){
var i= 0;
var array1 = val.value.split("\n");
for ( i = 0; i < array1.length; i++) {
array1[i] = "[img]" + array1[i] + "[/img]";
}
val.value = array1.join("");
}
</script>
The script above is suppose to be adding a prefix and suffix to multiple lines in a text area.
<textarea onClick="SelectAll('data');" name="data" id="data" cols="100" rows="20" ></textarea>
<input type="button" name="submit1" value="Submit" onclick="TextDefine(document.getElementById('data'))" />
example:
[img]first line[/img]
[img]second line[/img]
But in opera browser, the output is like this:
[img]first line
[/img][img]second line
[/img]
How do i fix this?
Upvotes: 0
Views: 303
Reputation: 1451
Oh i fixed it :D
i made the line
var array1 = val.value.split("\n");
to
var array1 = val.value.split("\r\n");
Then the line
array1[i] = "[img]" + array1[i] + "[/img]";
to
array1[i] = "[img]" + array1[i] + "[/img]\r\n";
It's fixed now :) Geez i solved my own probem :)
Upvotes: 1
Reputation: 5692
Is this coming from a textarea? Opera uses \r\n as a line separator in textareas, so try using var array1 = val.value.split(/\r?\n/);
.
Upvotes: 3