473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

inporting many lines of HTML through javascript

mikek12004
200 100+
I want to do this

Expand|Select|Wrap|Line Numbers
  1. msg='
  2. <div> 
  3.   mike
  4. </div>
  5. ';
  6. document.getElementById("sme_cont").innerHTML=msg;
  7.  
The problem is that the msg variables sees the '\n' character and prompts and error. If I put all the HTML code of the variable in one line works OK but inside the msg variable I plan to put complex HTML code so the ability to put it in multiple line is essential how can I do this?
Jul 20 '09 #1
6 1684
gits
5,390 Expert Mod 4TB
you may use concats like:

Expand|Select|Wrap|Line Numbers
  1. var foo = 'first line'
  2.     + 'second line'
  3.     + 'third line';
  4.  
or:
Expand|Select|Wrap|Line Numbers
  1. var foo = [
  2.     'first line',
  3.     'second line',
  4.     'third line'
  5. ].join('');
kind regards
Jul 20 '09 #2
Canabeez
126 100+
There's another workaround, if you use like Notepad++ or PSPAD, you could use a single line HTML in a variable and replace the "\n" to let's say "<!--NEWLINE--> in your HTML. So whenever you need to work in it you just replace the <!--NEWLINE--> to "\n" and the opposite. This is not the best solution, but it works ;)
Jul 23 '09 #3
Dormilich
8,658 Expert Mod 8TB
you can also escape the newline:
Expand|Select|Wrap|Line Numbers
  1. var msg = "some very \
  2. long text";    
  3.  
though it won’t preserve the line break.
Jul 23 '09 #4
Canabeez
126 100+
@Dormilich
Never knew this was possible, well we learn something new everyday... ;)
Jul 23 '09 #5
Dormilich
8,658 Expert Mod 8TB
I just stumbled upon that recently…
Jul 23 '09 #6
rnd me
427 Expert 256MB
if you have lots of text, a hidden input or textarea lets you store it without encoding. in a script file, you have to encode it.

i wrote a couple firefox batches to help.
just go to the link, click the "x" tab on the left.
then paste in your text, click "run", and click back on the "y" tab to view the results.

this string quoter one converts text into this format:
Expand|Select|Wrap|Line Numbers
  1. "dddd"+
  2. "eeee"+
  3. "gggg"
this slash adder produces the format shown by canabeez.

the JSONString version is an old standby, though it makes it hard to read.
Jul 25 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

26
by: Shannon Jacobs | last post by:
Sorry to ask what is surely a trivial question. Also sorry that I don't have my current code version on hand, but... Anyway, must be some problem with trying to do the negative. It seems like I get...
1
by: KathyB | last post by:
Hi, I'm using xml transformed to html via xsl. The problem is my HTML source text auto wraps/breaks lines. This only matters when the line involves a parameter I'm passing to a script...which then...
6
by: mr_burns | last post by:
hi, is it possible to have a string variable to contain new lines. i tried the following but it didnt work: var_string = '<h1>Title</h1> <img src="image.gif> <p>Body text</p>'; i know...
2
by: Iver Erling Årva | last post by:
Anyone know how I can get a printer to print thin lines using html print? 1 pixel is the least on screen, but that shows up as 4points or something like that on a laser. I would like to have that...
10
by: kaczmar2 | last post by:
Hey there, I have a large image in a browser window, and I would like a way to overlay grid lines on top of the image, so a user can show the grid or hide the grid lines. The grid would cover...
0
by: Romulo NF | last post by:
I´ve recently posted a script to move columns from a table using drag and drop javascript. Recently i´ve received a message of a user of this communty showing interest in the script to move lines...
3
by: ckirchho | last post by:
Hallo, my task is to establish some kind of full text file search in Javascript. The files and it's contents are fixed, the HTML/JavaScript pages lie offline on a server. As far as Javascript...
3
by: jackson.rayne | last post by:
Hello, Another newbie question here. Let me explain my situation first. I have bought a 3rd party tool that runs a PHP script and gives me some HTML code which I can directly use in my...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.