473,326 Members | 2,173 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,326 software developers and data experts.

line breaks in alert box from html script

I'm building an HTML page with javascript. All is fine in the document.write until I want to create an alert box from an onClick on the page.
Here's the script(part) so far:"<td><a href onclick=alert('Some&nbsp;list&nbsp;here')>The list</a></td>".
This brings back alert box with - Some list here - OK but I want a line break where the second &nbsp; is. I've tried all the \n \r <br> and <p> and %0A combinations I can think of.
Any ideas please. Remember that " doesnt work because the script is aleady within double quotes. ps I cant get a var to work from inside the script either !?
Oct 14 '11 #1

✓ answered by Humphrey Shires

Many thanks gits but that doesn't work, the problem is how html reads the script passed over from js - but I've now sussed it (after a few hours) -- the \n needs an escape in front of it ie \\n.
Posted for others is the part of document.write that applies (note the quotes):
"<table><tr><td><a href onclick=alert('Some&nbsp;list\\nhere')>The list</a></td></tr></table>".
Try this in a table created from js and click on the words 'The list'
Thnx to all who looked at it for me

4 3637
gits
5,390 Expert Mod 4TB
in an alert \n should work:

Expand|Select|Wrap|Line Numbers
  1. alert('foo\nbar');
and of course can you use a variable, JavaScript is a programming language so you would be lost without that possibility.
Oct 14 '11 #2
Many thanks gits but that doesn't work, the problem is how html reads the script passed over from js - but I've now sussed it (after a few hours) -- the \n needs an escape in front of it ie \\n.
Posted for others is the part of document.write that applies (note the quotes):
"<table><tr><td><a href onclick=alert('Some&nbsp;list\\nhere')>The list</a></td></tr></table>".
Try this in a table created from js and click on the words 'The list'
Thnx to all who looked at it for me
Oct 14 '11 #3
gits
5,390 Expert Mod 4TB
basically the following is not really valid:

Expand|Select|Wrap|Line Numbers
  1. <a href onclick=alert('Some&nbsp;list\\nhere')>
and should be:

Expand|Select|Wrap|Line Numbers
  1. <a href onclick="alert('Some&nbsp;list\nhere')">
is the shown code a snippet in a php script? in case it is then in fact it will turn out as:

Expand|Select|Wrap|Line Numbers
  1. <a href onclick=alert('Some&nbsp;list\nhere')>
later when the page is rendered. but attribute values should be enclosed in (double-) quotes
Oct 14 '11 #4
Hi gits, I've now replaced the text(between the 's in the alert box) with a variable. Had problem getting this to work until I entered the variables in the <script> section of the page <head>. I couldn't use double quotes in your example because all this snippet was inside a set of doubles to produce a row of a table. The project is for in-house so whatever works without bringing down the ceiling should be OK. The \\n works in the text variable and (bonus) &nbsp; is not needed: eg var strText = 'amounts\\n\\n1st\\nDue - $120.37'
Once again many thanks
Oct 14 '11 #5

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

Similar topics

1
by: Bill | last post by:
I am downloading data from a website that displays it in a table $fp = fopen("a website page", 'r'); The following accesses the stream one <td> element at a time $myData = fgets($fp); Then I...
5
by: mailbox | last post by:
Did write it down once, but have forgotten !! How is it you should format your ASP code to that when viewing the resulting HTML text from the browsers "view code" it looks nice with line breaks?
3
by: 'bonehead | last post by:
Okay, I haven't studied javascript at all and now it's starting to bite me because I suddenly find myself needing to use some in my php/mysql web database. What is the syntax for producing line...
11
by: Johnny Two Dogs | last post by:
I'm strictly concerned with IE, so cross-browser compatibilty isn't necessary. If you view the code below, I almost get exactly what I'm looking for: - A table of four cells that...
2
by: Andrew Banks | last post by:
I have a text box which allows users to input the content for a HTML email. I need to maintain the line breaks as the user enters them in the text box when I send the email. I'm assuming I need...
5
by: joelbyrd | last post by:
Didn't know exactly where to post this, but: How do I get line breaks in a textarea? I'm pulling text from a database, and this text definately has line breaks in it, because I replaced all the...
14
by: ghostwalker | last post by:
Hi I have an HTML form with a textarea on it. When submitted (using 'get' not 'post') this forms action php file simply does this to retrieve the values: $message = $_GET; Now it all works...
3
by: Wayne Deleersnyder | last post by:
Hi All, I'm trying to create a function that will cause a pop-up alert to appear if dates which were chosen from a drop-down list were invalid on a page. There's 4 dates, so there's the...
20
by: alice | last post by:
I'm doing some text swapping with javascript, got it working fine, but I would like the line to have line breaks and being a beginner, I don't even know if this is possible. So I have a line like...
4
by: Velhari | last post by:
Hi all, I wrote the following Javascript function used to execute the Javascript codes from the ajax response which contains both html & javascript. It works fine, if the javascript codes from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.