Hi everyone ..
i am trying to use a string which was saved by php form and contain
single quote ' or double quote
" .. when i using that string in my js script function like
function
onclick='js_tes t("<?=$string;? >")'
if $string contains double quote it will simply break the function ..
and same goes for single quote if i
surround $string with single quote i tried using escape and unescape
but that means .. every place i am using php ddata which might contain
single or double quote i have to use those javascript
function . as i am very new to programming if somebody could advise
what is the best way to deal
with string when we use js script and php
hope you can understand my english and hope somebody will reply soon
thanks 6 1515
It's generally considered best practices to wrap HTML elements in
double quotes.
So, your onclick event handler should look like this:
onclick="js_tes t('<?php echo $string; ?>');"
(Note that it is also considered good form to use <?php ... ?to
denote PHP code at all times.)
Depending on the contents of $string, you might also want to use the
addslashes() function, like so...
onclick="js_tes t('<?php echo addslashes($str ing); ?>');"
Hope this helps.
On Dec 8, 9:51 pm, php_mysql_begin er911 <deepa...@gmail .comwrote:
Hi everyone ..
i am trying to use a string which was saved by php form and contain
single quote ' or double quote
" .. when i using that string in my js script function like
function
onclick='js_tes t("<?=$string;? >")'
if $string contains double quote it will simply break the function ..
and same goes for single quote if i
surround $string with single quote i tried using escape and unescape
but that means .. every place i am using php ddata which might contain
single or double quote i have to use those javascript
function . as i am very new to programming if somebody could advise
what is the best way to deal
with string when we use js script and php
hope you can understand my english and hope somebody will reply soon
thanks
..oO(st******** @gmail.com)
>It's generally considered best practices to wrap HTML elements in double quotes.
Attributes. And both single and double quotes are perfectly valid. In
this case it might make a difference because of the JS, but usually it
doesn't matter.
Micha
On Dec 9, 6:11 am, Michael Fesser <neti...@gmx.de wrote:
.oO(steve.h...@ gmail.com)
It's generally considered best practices to wrap HTML elements in
double quotes.
Attributes. And both single and double quotes are perfectly valid. In
this case it might make a difference because of the JS, but usually it
doesn't matter.
Micha
XHTML allows you to use both single or double, but it's best to use
the double quotes since it's what most people expect.
Also, addslashes is perfect for this problem. Sounds like you'll need
to sanitize the string with htmlspecialchar s.
My 2 cents,
Allain
..oO(allain)
>XHTML allows you to use both single or double, but it's best to use the double quotes since it's what most people expect.
Who expects that?
Micha
On Mon, 10 Dec 2007 21:25:48 +0100, Michael Fesser <ne*****@gmx.de wrote:
.oO(allain)
>XHTML allows you to use both single or double, but it's best to use the double quotes since it's what most people expect.
Who expects that?
Apparantly, some very, very bad parsers(1). And as XHTML is rendered as
tag soup most of the time anyway, and it's perfectly legal to use either
one, just take your pick. I just prefer double quotes because that's what
I'm used to, no other greater good in mind then ease of code :).
(1) http://worsethanfailure.com/Articles...ion-Error.aspx
--
Rik Wasmus
..oO(Rik Wasmus)
>On Mon, 10 Dec 2007 21:25:48 +0100, Michael Fesser <ne*****@gmx.de wrote:
>.oO(allain)
>>XHTML allows you to use both single or double, but it's best to use the double quotes since it's what most people expect.
Who expects that?
Apparantly, some very, very bad parsers(1). And as XHTML is rendered as tag soup most of the time anyway, and it's perfectly legal to use either one, just take your pick. I just prefer double quotes because that's what I'm used to, no other greater good in mind then ease of code :).
That's perfectly OK. I also usually use double quotes, but often enough
I use single quotes, if it makes my PHP code more readable:
print "<img src='$someVar' alt='...'>\n";
vs.
print "<img src=\"$someVar\ " alt=\"...\">\n" ;
or
print '<img src="'.$someVar .'" alt="...">'."\n ";
I definitely prefer the first one. Every browser accepts it and for the
website user it doesn't matter at all.
Micha This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: DeepBleu |
last post by:
When one is using an HTML form via a web broswer, the user submits the form
contents and these are passed to a CGI Python script on the web server.
I need to write a client script that connects to a web site, runs a Python
CGI script on the web server AND passes a string to the CGI Python script
that the Python CGI script can store/manipulate/evalute etc....
I know how to connect to the web site and run the CGI Python script using a
client...
|
by: John F Dutcher |
last post by:
Having 'cloned' an existing python script that imports 'string' and
uses "string.rstrip()" without incident...
I am at a loss to explain why the new 'cloned' script (brief sample
below) continually errors with:
NameError: global name 'string' is not defined
args = ("global name 'string' is not defined",)
when run from the server CGI-BIN.
If the same script is run in 'IDLE' it
|
by: news-server.tampabay.rr.com |
last post by:
Hi,
Below is a stock script I found which controls a framed environment.
My problem is that if a URL has a query string attached, that string
does not pass through. Can someone please let me know if and
hopefully how, it will be possible to carry a query string through?
This first part here is in the default.asp framed page.
<SCRIPT LANGUAGE="JavaScript">
|
by: lkrubner |
last post by:
I'd like to write a PHP script to be used from the command line on a
Unix machine. I'd like for the script to put together a string, turn it
into a web page, print it, then return control the command line.
Obviously it is quite easy to make a string that is valid HTML and send
it to the printer. The tough part is making look like a web page. In
particular, image tags should print out as images, not image tags.
Does anyone have an idea...
|
by: tshad |
last post by:
In my User control, I tried to do this:
***************************************************************************
<Script runat="server">
Public ClientName As String = "<!-- #include file =
...\includes\StaffingHeaders.inc -->"
</Script>
<%=ClientName%>
****************************************************************************
| |
by: Alan Silver |
last post by:
Hello,
I have noticed in a few bits of code that people sometimes do things
like...
SomeFunction(@"a text string");
What is the purpose of the @ sign? I have seen it most when passing
connection strings (admittedly in example code, as connection strings
would be better stored elsewhere in a real app), but I don't think it's
|
by: Ed Jay |
last post by:
<disclaimer>js newbie</disclaimer>
My page has a form comprised of several radio buttons. I want to poll the
buttons to determine which button was selected and convert its value to a
string. I then want to use the string on the same page.
My script is:
function checkRadio(field) {
for(var i=0; i < field.length; i++) {
|
by: Alex |
last post by:
Hello.
First, with AJAX I will get a remote web page into a string. Thus, a
string will contain HTML tags and such. I will need to extract text
from one <span> for which I know the ID the inner text.
Is it possible to access in this way "string variable".getElementByID()
somehow?
Thank you.
|
by: shapper |
last post by:
Hello,
I am creating a string using StringBuilder:
Dim code As New StringBuilder
code.Append("<script type=""text/javascript""><!--")
Response.Write(code.ToString)
However, I don't get any code when I do Response.Write.
|
by: shapper |
last post by:
Hello,
I have an Action where I define a ViewData property named Ad:
public ActionResult GoogleAdSense(string client, int height,
string slot, int width) {
StringBuilder ad = new StringBuilder();
ad.AppendLine("<script type='text/javascript'>");
ad.AppendLine("<!--");
ad.AppendLine(String.Concat("google_ad_client = '", client,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |