473,386 Members | 1,969 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,386 software developers and data experts.

Outputting variables in javascript confusion


I'm confused -

The following outputs a URL encoded string into an alert box
----------------------CUT ----------------------
function createEmbarrasment() {
$tmp = urlencode("Your fly is undone!");
?<script type="text/javascript"><!--
alert('<?php echo $tmp; ?>')
//--</script>
<?php
}
-------------------------------
Unfortunately displaying the URL encoded version of the string

If you remover the URL encoding the alert box doesn't even display

Next

Using constants - Again this fails to even open the alert box
----------------------CUT ----------------------

function createEmbarrasment() {
define("TEMP","Your fly is undone!");
?<script type="text/javascript"><!--
alert('<?php echo TEMP; ?>')
//--</script>
<?php
}
-------------------------------

AND YET

----------------------CUT ----------------------
function createEmbarrasment() {
?<script type="text/javascript"><!--
alert('<?php echo PHP_VERSION; ?>')
//--</script>
<?php
}
-------------------------------
Opens the box and displays fine without URL encoding

MY PROBLEM - I'm trying to do the first example without the display
showing the URL encoding.
Can anyone explain or help please?

-andy-

Mar 9 '07 #1
2 1396
Rik
<an****@blueyonder.comwrote:
The following outputs a URL encoded string into an alert box
URL encoding is for, well URL's, not for text, prompt or alerts. Drop
that, unless you want to alert(?) how urlencoding looks like.
If you remover the URL encoding the alert box doesn't even display
Does here, as long as $tmp is set.
We're not in a javascript group here, and all your issues are related to
javascript itself. Wether this is dynamically build or hardcoded does not
matter to the browser (heck, it doesn't even know it).

Just look at the _source_ of you generated HTML-document, check what's
wrong with the javacript, and adjust the output oh PHP accordingly.
--
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel
Mar 9 '07 #2
On Fri, 09 Mar 2007 17:50:48 GMT, in comp.lang.php
an****@blueyonder.com
<MP**********************@news-text.blueyonder.co.ukwrote:
>|
| I'm confused -
|
| The following outputs a URL encoded string into an alert box
| ----------------------CUT ----------------------
| function createEmbarrasment() {
| $tmp = urlencode("Your fly is undone!");
| ?<script type="text/javascript"><!--
| alert('<?php echo $tmp; ?>')
| //--</script>
| <?php
| }
| -------------------------------
| Unfortunately displaying the URL encoded version of the string
|
Javascript alert boxes are plain text. So if you use
alert("This is line 1<br />This is line 2");
then This is line 1<br />This is line 2 will be displayed

To show the above correctly you need
This is line 1\nThis is line 2

Change your $tmp variable to
$tmp = "Your fly is undone!";
---------------------------------------------------------------
jn******@yourpantsyahoo.com.au : Remove your pants to reply
---------------------------------------------------------------
Mar 10 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Oleg Konovalov | last post by:
Hi, I am trying to pass a bunch of checked checkboxes (Javascript array) from page1 to the Java action class on subsequent web page (page2). (on page 1 I have a bunch of DB rows with a checkbox,...
13
by: Jake Barnes | last post by:
I saw this sentence: "The last stage of variable instantiation is to create named properties of the Variable object that correspond with all the local variables declared within the function." ...
10
by: jason_box | last post by:
Hello, I was wondering if there was a way to have a javacript be activated by an input button that would call to a cgi program and querey every 10minutes and the cgi would update the page without...
4
by: Lando | last post by:
I'm a bit confused ...javascript and jscript are the same thing ? javascript and java are related.......... javascript in windows differs from javascript in linux....? Sorry,... if some question...
9
by: skijor | last post by:
I am converting a raw html webiste to use javascript. A lot of the html code is duplicated in many pages. Some of that code can be consolidated into javacript but I don't want to add the same...
4
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
17
by: Matt | last post by:
Hello. I'm having a very strange problem that I would like ot check with you guys. Basically whenever I insert the following line into my programme to output the arguments being passed to the...
1
Markus
by: Markus | last post by:
Little problem here. How would i go about outputting "&raquo;" through giving something a value. i.e. if(validateEmail(emailValue) === false){ emailStyle.color = "red"; emailText.value...
34
by: dhtml | last post by:
I made a change to the FAQ of javascript to EcmaScript. I got some feedback that the newsgroup is CLJ and the language is commonly referred to as JavaScript. Therefore, the word in the FAQ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.