document.write

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

document.write

Post by shiznatix »

I am trying to have a javascript and a no javascript option for this page I am making. I am just putting the non javascript stuff in <noscript> tags and the javascript stuff I am trying to write out with document.write but...

When I use document.write() I get the error in my FF error console "undetermined string literal" and it points to the first quote mark. here is what I am trying:

Code: Select all

<script type="text/javascript">
    document.write("
        <a href=\"Products.php?Action=Remove&Id='.$val->Get('Id').'\" 
            onclick=\"return confirm(\''.PR_DO_YOU_REALLY_WANT_TO_DELETE_THIS_PRODUCT.'\')\">
        Del</a>
    ");
</script>
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

try this:

Code: Select all

<script type="text/javascript">
    document.write("<a href=\"Products.php?Action=Remove&Id='.$val->Get('Id').'\"  onclick=\"return confirm(\''.PR_DO_YOU_REALLY_WANT_TO_DELETE_THIS_PRODUCT.'\')\">Del</a>");
</script>
that should all be one line.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I like this method...

Code: Select all

var element = document.getElementById('replace_link');
element.href = '#';
element.onclick = action_you_want_to_perform();
And then in your html...

Code: Select all

<a id="replace_link" href="non-javascript-page.html">Hey dude</a>
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

I thought the concatination operator was + in JavaScript, not .
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Burr: thanks, i didn't know the 1 line rule.
Ninja: Good method but I want a link to show up for JS and a checkbox to show up for noscript
jay: it is, the concatination I am using is for PHP ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

shiznatix wrote:Burr: thanks, i didn't know the 1 line rule.
Ninja: Good method but I want a link to show up for JS and a checkbox to show up for noscript
jay: it is, the concatination I am using is for PHP ;)
You could have a <span> with the checkbox in it and set to some class that you can then dig out via the DOM and switch out the contents of the <span> to your link...
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

document.write is oldschool... do what feyd said.
Post Reply