Page 1 of 1

document.write

Posted: Wed Dec 06, 2006 10:35 am
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>

Posted: Wed Dec 06, 2006 10:39 am
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.

Posted: Wed Dec 06, 2006 10:41 am
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>

Posted: Wed Dec 06, 2006 10:44 am
by jayshields
I thought the concatination operator was + in JavaScript, not .

Posted: Wed Dec 06, 2006 1:11 pm
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 ;)

Posted: Wed Dec 06, 2006 1:14 pm
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...

Posted: Wed Dec 06, 2006 1:17 pm
by Luke
document.write is oldschool... do what feyd said.