Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Line break in javascript alert using xajax

Posted on 2009-04-09
Medium Priority
Last Modified: 2013-12-13
How would you encode this variable to include line breaks? I have tried <br>, \n, \r\n it hanges up with all of them.

$myhtml = " Count: ". $row . " Taxid: ". $taxid . "\r\n Legal: " . $sub . " " . $blk . " " . $lot . " \r\nOwner: ".$fname . " " . $lname;

$objResponse->script("alert(myhtml = '$myhtml';")

Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
LVL 39

Expert Comment

by:Roger Baklund
ID: 24112402
You must double the backslashes, and the alert call is wrong:

$myhtml = " Count: ". $row . " Taxid: ". $taxid . "\\r\\n Legal: " . $sub . " " . $blk . " " . $lot . " \\r\\nOwner: ".$fname . " " . $lname;


Author Comment

ID: 24112443
Did not work still no line breakes.  I add another one since google is using it to in the marker popup.
That did not work either.  Any other ideas?

$myhtml = " Count: ". $row . " Taxid: ". $taxid . "\\\r\\\n Legal: " . $sub . " " . $blk . " " . $lot . " \\\r\\\nOwner: ".$fname . " " . $lname;

LVL 39

Expert Comment

by:Roger Baklund
ID: 24112457
Two backslashes works for me. What kind of values are in the other variables? You can not have linefeeds or apostrophes.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 24112530
I am trying to do an alert to see if the alert has line breaks. missing some thing on quatoes.
$objResponse->script("row=$row;taxid = $taxid;alert('myhtml=\'$myhtml\';taxid = $taxid'');");
LVL 39

Expert Comment

by:Roger Baklund
ID: 24112565
You have a syntax error in your alert() call. Correct syntax is:


So in the PHP string above, it should be:

$objResponse->script("row=$row;taxid = $taxid;alert('$myhtml');");

Author Comment

ID: 24112587
works in the alert.  but not in the google marker popup using the same vairable.
I could live with the alert instead of the google marker except that I need to put links in the popup to get additional information if the user chooses. Can that be done in a alert?
LVL 39

Accepted Solution

Roger Baklund earned 2000 total points
ID: 24112679
No, the javascript alert can not have links, just plain text.

I think the google marker popup is html-based, so \n will not work there, but <br /> should work.

Author Comment

ID: 24112793
that did it.  thank you! This stuff is comming together, but slowly.  php,xaxjax, javascript, html,filemaker. A lot to learn all at once. I think my biggest problem is mixing syntax between platforms.

Author Closing Comment

ID: 31568773
thanks again.  I appreciate your quick responses.  

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question