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 9016667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:03:30+00:00 2026-06-16T04:03:30+00:00

Couple questions: 1) I’m trying to have a new random value updated each time

  • 0

Couple questions:

1) I’m trying to have a new random value updated each time a button is pressed. When the button is clicked, a value is generated once… but is not random. So I’m not sure if the function is being called again on click because a new value isn’t generated.

2) Can I include the php code within the same file as the jquery when using a server call such as $.get() and call it as a function within that same file?

The reason is, I don’t want to have to keep creating new php script files, and would rather throw the code in the same file as the calling jquery.

Meaning…

Instead of $.get("../scripts/NameGenerator2.php",

I do this: $.get("a php function within this same file",

JQuery:

<?php 
   if ($imgid == 1) {
?>
<button onclick="generate()">Generate</button>

<button id="generateButton">Generate</button>

<script type="text/javascript">
    $(document).ready(function() {
        $("#generateButton").click(function(e) {
            //alert("called");
           $.get("../scripts/NameGenerator2.php", 
                function(returned_data) {
                    $("#generated").html(returned_data);
                }
            ).error(function(jqXHR, status, error) {
                console.log("error in $.get")
            });
        });
    });
</script>       
<?php } ?>
<br /><span id="generated"></span><br />

PHP:

<?php 
$adj = array("Happy", "Great", "Mandarin", "New", "Golden", "Ming's");
$noun = array("Dragon", "Sea", "Wok", "Fortune", "Rice", "Empire");
$place = array("Garden", "China", "Village", "Palace", "Kitchen", "Mountain");


$x = rand(0, count($adj)-1);
$y = rand(0, count($noun)-1);
$z = rand(0, count($place)-1);

echo '<p>' . $adj[$x] . " " . $noun[$y] . " " . $place[$z] . '</p>';

?>

Any thoughts? Thanks!

Updated: Only error I seem to be getting is “Object Expected” in my “myJquery.js” file, which is not the file I’m working in, and doesn’t seem connected.

enter image description here

When I add in document ready to my function, the button onclick() call seems to break.

enter image description here

  • 1 1 Answer
  • 0 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-06-16T04:03:32+00:00Added an answer on June 16, 2026 at 4:03 am

    You cannot get a PHP function but you can load the page and get a specific div –

    $('#generated').load('../scripts/NameGenerator2.php #pagePart');
    

    You echo out PHP with the proper id’s in place, for instance –

    echo '<p id="pagePart">' . $adj[$x] . " " . $noun[$x] . " " . $place[$x] . '</p>';
    

    Without using any inline JavaScript this is what your jQuery code might look like –

    <button id="generate">Generate</button>
    
    $(document).ready(function() {
        $('#generate').click(function(e){
            e.preventDefault();
            $('#generated').load('../scripts/NameGenerator2.php #pagePart');
        });
    });
    

    Based on your update you need to move all of your jQuery functions into the document ready function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement facebook connect to my website, and i have couple questions.
I have a couple questions. This is an example of what i'm trying to
I am trying on RX for the first time and I have a couple
Have a couple questions, using GSON. I have a feeling that GSON might not
I have a couple questions about SSL. What happens if someone tampers or changes
I have a couple questions about exceptions. 1) when you hit a catch block,
I have couple questions regarding some C++ rules. Why am I able to call
I have a couple questions about submitting blue-tooth enabled apps on the iPhone. I
I have a couple questions about creating a object (2 values) and how to
i have a couple questions about an idea i have to manage a form

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.