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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:18:19+00:00 2026-06-12T14:18:19+00:00

I’am trying to random select modal dialog and end after specific number of click.

  • 0

I’am trying to random select modal dialog and end after specific number of click.

I’am new at javascript and this is what i got so far.

<script type="text/javascript">
var randomNumber = Math.round(Math.random()*4+1);
function myclick(){

if (randomNumber == 1) {
    $("#q1").click();
}

if (randomNumber == 2) {
    $("#q2").click();
}

if (randomNumber == 3) {
    $("#q3").click();
}

if (randomNumber == 4) {
    $("#q4").click();
}
}
</script>

<body>
<a id="q1" href="#dialog1" name="modal" image=></a>
<a id="q2" href="#dialog2" name="modal" image=></a>
<a id="q3" href="#dialog3" name="modal" image=></a>
<a id="q4" href="#dialog4" name="modal" image=></a>

UPDATE!!!!!!!!!!!!!!!!!!!!!!!!
thanks for the fast reply.

Iam sorry not included all the script.

<script type="text/javascript" src="jquery.1.8.2.js"></script>
<script>

var randomNumber = Math.floor(Math.random()*4+1);


function myclick(){
if (randomNumber == 1) {
    $("#q1").click()
}
else if (randomNumber == 2) {
    $("#q2").click()
}
else if (randomNumber == 3) {
    $("#q3").click()
}
else if (randomNumber == 4) {
    $("#q4").click()
}
}
</script>

<BODY>

<h3>Web Design Quiz</h3>
<form name="quiz">
<a id="q1" href="#dialog1" name="modal" image=></a>
<a id="q2" href="#dialog2" name="modal" image=></a>
<a id="q3" href="#dialog3" name="modal" image=></a>
<a id="q4" href="#dialog4" name="modal" image=></a>
<input type="button" src="img/info.png" onclick="myclick()"></input>

I removed close”;” after “Round” and add “else if”. i still can only open 1 dialog at a time. I would like to open all dialog by clicking the button and end with the last one. how to refresh my random number everytime a click the button?

  • 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-12T14:18:20+00:00Added an answer on June 12, 2026 at 2:18 pm

    OK, firstly I hope you are aware you are using JQuery and have therefore including the correct scripts. Something like:

    <script src="/Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    

    next for a list of issues:

    • You don’t close the random Round function
    • Your random number is set as a global variable and will only be set once (and not changed), but maybe this is your desire. If you need it different each time you should consider moving it inside of the myclick function
    • You don’t appear to be calling the myclick function anywhere, but maybe this is done inline?
    • Calling the JQuery click function is not ideal for simulating a click. It would be better to create a separate function that takes the selector id for the div that should be processed

    TIP: You can do this kind of thing with less code by custom building the JQuery selector which will save you having all the if statements. Something like:

    $("#q" + randomNumber).click();
    

    Also, using multiple if statements like this should make use of the else if statement too, because in this instance only one if statement can ever be successful

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.