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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:27:44+00:00 2026-05-28T00:27:44+00:00

I am a beginner in all Javascript stuff and the code is making me

  • 0

I am a beginner in all Javascript stuff and the code is making me crazy.
I’m using Jquery

I have a div:

<div id="dicesDiv"></div>

This div is load at the beginning directly with this code:

$("#dicesDiv").load("dices.php?dice1=<?php print ($lastDices[1])?>&dice2=<?php print
($lastDices[2])?>");

I have a link to reload this div when clicking it:

<a href = "javascript:void(0);" onclick = "javascript:rollDice();"><img src="../images
/tirar_dados.png"/></a>

This is all my javascript stuff:

<script>
......

function rollDice()
{
    <?php $lastDices[1] = rand(1,6);?>
    <?php $lastDices[2] = rand(1,6);?>
   $("#dicesDiv").load("dices.php?dice1=<?php print ($lastDices[1])?>&dice2=<?php print
   ($lastDices[2])?>"); 
}
</script>

When I click the first time, it works, but when I click later it doesn’t work. It doesn’t make sense to me.

Do you know what is happening??

Thanks ^^

  • 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-05-28T00:27:44+00:00Added an answer on May 28, 2026 at 12:27 am

    Your PHP code executes once, when you first load the page.

    Therefore, every click uses the same numbers.
    Instead, you should generate the numbers in Javascript by writing

    1 + Math.floor(Math.random() * 6)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a beginner with javascript ajax, and all this web stuff. I have
First of all, Beginner here. I'm using this code. class MDArrays { public static
Absolute beginner question: I have a template file index.html that looks like this: ...
I am a COMPLETE beginner at JQuery (and javascript in general) but I'm having
OK - I'll admit, I'm quite a beginner in this jQuery-department. I've probably made
This is my second day of doing anything at all with javascript so I
HI ALL I'm a beginner in SilverLight.I have three controls in a canvas which
So I'm a beginner at this whole javascript thing, and this is probably a
am a beginner, writing one interface to create a dynamic menu(cascading) using html, javascript
HI All, I'm a veritable JS beginner and thus I've been using some simple

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.