View Full Version : Javascript and quoting

04-30-2004, 09:33 PM
When you use a writeln() or write() command, we all know how to work with strings.

Basically, if you want java to write the HTML equavlent of, say:
<table color="red">

you would write:
document.writeln("<table color='red'>");

but now, I need to write out this line:
<select name="Gnetwork" onchange="MM_jumpMenu('parent',this,0)">

How would I run it through as a writeln command? (because theres already ' ' characters)

document.writeln("<select name='Gnetwork' onchange='MM_jumpMenu(?parent?,this,0)'>");

what would I replace the ?'s with?

Roy Sinclair
04-30-2004, 09:49 PM
How I'd do it:

document.writeln("<select name=\"Gnetwork\" onchange=\"MM_jumpMenu('parent',this,0)\">");

05-01-2004, 12:16 PM
i just spent about 4 days trying to figure this out (for a couple languages) and in javascript:

no diff, as long as they come in pairs - in theory... but in praxis most folks (from what they tell me) follow a double with a single (first in first out) like


- since it is returning a string, it must have one or the other.

if it's not returning a string, it cannot have either.

for example "somefunction(this)" or "somefunction(obj)" would be fine

i really don't know my head from a hole in the ground in re: script, but i think this info's right since it just happened and i'm just mumming the guys that know what they're doing (on this board).

without using roy's suggested slash method, i think it would be this (but i'm not sure):

document.writeln("<select name='Gnetwork' onchange='MM_jumpMenu(parent,this,0)'>");

i'm too lazy to look it up at the moment, but not more than a week ago i had a thread on this topic where brothercake and glenngv broke it down pretty clearly (cos i'm stupid ;)). gl.

edit: punctuation.

05-01-2004, 01:12 PM
I believe that you can use character entities:

<select name="Gnetwork" onchange="MM_jumpMenu(&#038;#039;parent&#038;#039;,this,0)">

If you wanted to surround parent in double quotes, you would use the character #034; or quot;

05-05-2004, 06:23 AM
How I'd do it:

document.writeln("<select name=\"Gnetwork\" onchange=\"MM_jumpMenu('parent',this,0)\">");

But I prefer this:

document.writeln('<select name="Gnetwork" onchange="MM_jumpMenu(\'parent\',this,0)">');

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum