![]() |
IOBit Software
|
|
|
||||||
| Programming Place to discuss programming including HTML, Java, C++, MySQL and others. |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hey everyone,
I have what I imagine is a pretty basic question but I am just getting into javascript. I want to create a new line break in a javascript message for my web app I am working on. Right now the dialog box pop up is too long and I want to just have two lines of text instead of all on one. The code I have is: string sJavaScript =""; sJavaScript = "<script language='javascript'>"; sJavaScript += "alert('Line1 '\n' Line2');"; sJavaScript += "</scr" + "ipt>"; Response.Write(sJavaScript); When I run that IE gives me a javascript error saying: Line: 2 Char: 1 Error: Expected ')' Code: 0 And no pop-up is displayed. if I remove the '\n' part than it displays just fine... but all on one line. if I remove the two apostrophe's and just have the \n in between the lines than I get an error that says "Unterminated string constant" and Line: 1 and Char: 78 Please ANY insight or advice as soon as possible would be greatly appreciated! TIA! |
| Sponsored links |
|
|
|
#2
|
|||
|
|||
|
Problem solved. Just in case anyone else ever comes across this problem. The solution is as follows:
Since I was using Visual Studios and adding all the J Script to a string variable THEN passing the string into it's runtime what I had written was " Line 1 \n Line 2" this was merely creating a new line in the runtime and not being processed as a new line in the alert box so the escape sequence of \n was not actually getting written into the runtime. So I simply needed to dereference the '\n' operation by using the following sintax alert('Line 1 \\n Line 2') That way the \n was getting carried through the string creation and being passed into the runtime. |
|
#3
|
||||
|
||||
|
string sJavaScript ="";
sJavaScript = @"alert('Line1 \n\r Line2');"; ClientScript.RegisterScriptBlock(this.GetType(),"__test",sJavaScript,true);
__________________
"The American people will never knowingly adopt Socialism..." -Norman Thomas Last edited by Kodo; 08-25-07 at 15:00.. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| javascript | yoduh | Programming | 1 | 06-02-07 14:19 |
| Javascript help | Computer Acolyte | Programming | 4 | 05-19-07 16:50 |
| Javascript | Uproot | Software | 2 | 01-22-06 15:47 |
| JavaScript help. | Publius | Programming | 0 | 12-02-05 10:06 |
| javascript | man_im_bored | Programming | 1 | 12-21-03 20:46 |