Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4117138
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:47:50+00:00 2026-05-20T22:47:50+00:00

Not sure if that title makes any sense but I’ll try and explain it.

  • 0

Not sure if that title makes any sense but I’ll try and explain it.

I am generating some content with PHP.

What I am attemtping to generate is a string that will spit out an URL with some JavaScript in the onlick event if the user has JavaScript enabled, and then a regular link if the JavaScript is not enabled.

$url = "<script type=\"text/javascript\">
    document.write(\"<a href='#' onclick='$('#UserID').val(" . 
            mysql_result($recordset, $count, "userid") . "); return false;'>
        Click here
    </a>\");
</script>
<noscript>
    <a href=\"/scripts/updateuser.php?id=" . 
            mysql_result($recordset, $count, "userid") . "\">Click here</a>
</noscript>"; 

The problem I am running into is the jQuery selector for #UserID. Since it’s single quoted it bombs out there when clicked and processes the hash mark and goes to the top of the page ignoring the return false.

I can’t put double quotes there because that’s at the start and end of my document.write statement.

Any ideas on how to structure the string around the jQuery selector here using escape characters or whatever?

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:47:51+00:00Added an answer on May 20, 2026 at 10:47 pm

    Good god that’s ugly. Try this on for size:

    $userid = mysql_result($recordset, $count, "userid");
    
    $url = <<<EOL
    <script type="text/javascript">
        document.write('<a href="#" onclick="$(\'#UserID\').val({$userid})); return false;">Click here</a>');
    /script>
    <noscript><a href="scripts/updateuser.php?id={$userID}">Click here</a></noscript>
    EOL;
    

    I won’t get into how 1990’s document.write is, but how about this:

    <?php
        $userid = ...
    ?>
    <a href="scripts/updateuser.php?id=<?php echo $userid ?>" onclick="$('#UserID').val({$userid}); return false;">Click here</a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure if the title makes any sense but here is the
Not sure if the title makes any sense. I have an object that I
Hmm not sure if the title of this makes any sense. I'm creating a
The title is hardly understandable, but I'm not sure how to summarize that another
I'll try to ask this in a way that makes some sense. I have
As the post title implies, I have a legacy database (not sure if that
I am not sure where i've seen this before, but im sure that there
I see this question here on SO but I am not sure that answers
I am sure the title of my question doesn't make much sense. But here
(The title may not be proper but I try my best to phrase it)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.