views:

69

answers:

2

The thing im trying to do right now is pulling in multiple links from a textarea,

We can pretend that a user inputs c:\pics\img01.jpg and in the next row he'll have the next imglink.

I want to pull those links, I allready have the code for that:

var entered = $('#filedir').val();  
var lines = entered.split(/\r\n/);  
var opttext = "";  
for(var i=0;i<lines.length;i++) {  
    opttext += '< img src="' + lines[i] + '">< /img>';
}
​

the problem is in the output which is:

< img src="file:///C:/pics/img01.jpgc:/pics/img02.jpg">< /img>

There should be two < img> elements..

Where am I going wrong? I've been at it for a bit over 2 hours now..

A: 
for(var i=0;i<lines.length;i++)
{
     opttext += '<img src="' + lines[i] + '"></img>';
}

Your for loop was incorrect.

webdestroya
.. i think its the same, i had to put the space between < img to make the thread allow me to write it out.. don't know how to do it otherwise, but thanks!
Noor
+3  A: 

It's likely that your lines aren't getting split correctly and you're ending up with one long line in the array. Try this instead:

var lines = entered.split(/\n/);  
Chris Pebble
Solved it!omg.. 2+ hours and all that was wrong was two characters..Thanks!!
Noor
@Noor: you should mark the answer as the accepted answer then.
David Murdoch
@David I did, it told me to wait 2 minutes.. just waited for it.. a bit too long i guess :p :)! thanks though
Noor
"this\r\nis\na\rtest".split(/\r?\n|\r/) \r for old mac, \n for linux/osx, \r\n for windows... sample above works for all three.
Tracker1