Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: JavaScript question if anyone can help. What's wrong with my code?

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy JavaScript question if anyone can help. What's wrong with my code?

    I am new to coding and am not sure what is wrong with my current code. Currently i'm using HTML and JS. Here is what I'm trying to do: Create a random number generator from values 1-4. I want the generator to initiate when a submit button is pressed. I get the generator to work and appear on the document however, once I try to switch it to the submit button it stops working. Any help would be highly appreciated. Here is what I have thus far:

    <html>
    <body>
    <textarea rows="1" cols="25" id="option1">
    </textarea>
    <textarea rows="1" cols="25" id="option2">
    </textarea>
    <textarea rows="1" cols="25" id="option3">
    </textarea>
    <textarea rows="1" cols="25" id="option4">
    </textarea>
    <button id="clickme" name="subject" type="submit" value="Submit">Submit</button>

    <p></p>
    <script type="text/javascript">
    var random = Math.floor(Math.random()*5)
    var number = function(random);
    $(".clickme").click(number) {
    if(number == 0 || number == 5) {
    document.write("Still thinking...Click again.");
    }
    else
    {
    document.write(number);
    }
    </script>
    </body>
    </html>


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default re: JavaScript question if anyone can help. What's wrong with my code?

    Welcome! Please read this topic to learn how to post code correctly and other useful info for new members.

    Just so you know, JavaScript is not Java. Moving thread to the appropriate sub-forum.

    Please give your threads meaningful titles that describe what your post is about, what you're asking for help with. "Unit?"

  3. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JavaScript question if anyone can help. What's wrong with my code?

    I am new to coding and am not sure what is wrong with my current code. Currently i'm using HTML and JS. Here is what I'm trying to do: Create a random number generator from values 1-4. I want the generator to initiate when a submit button is pressed. I get the generator to work and appear on the document however, once I try to switch it to the submit button it stops working. Any help would be highly appreciated. Here is what I have thus far:

    <html>
    <body>
    <textarea rows="1" cols="25" id="option1">
    </textarea>
    <textarea rows="1" cols="25" id="option2">
    </textarea>
    <textarea rows="1" cols="25" id="option3">
    </textarea>
    <textarea rows="1" cols="25" id="option4">
    </textarea>
    <button id="clickme" name="subject" type="submit" value="Submit">Submit</button>

    <p></p>
    <script type="text/javascript">
    var random = Math.floor(Math.random()*5)
    var number = function(random);
    $(".clickme").click(number) {
    if(number == 0 || number == 5) {
    document.write("Still thinking...Click again.");
    }
    else
    {
    document.write(number);
    }
    </script>
    </body>
    </html>

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: JavaScript question if anyone can help. What's wrong with my code?

    Duplicate threads merged.

Similar Threads

  1. JavaScript question if anyone can help. What's wrong with my code?
    By eprunier1 in forum Other Programming Languages
    Replies: 0
    Last Post: March 1st, 2014, 09:51 AM
  2. Help needed - Embedding javascript code in JSP code.
    By chinnu in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: October 29th, 2012, 01:09 PM
  3. JavaScript code
    By Swathip in forum Other Programming Languages
    Replies: 1
    Last Post: July 30th, 2012, 09:36 AM
  4. Floating Balloons Javascript Code Help
    By Website Designer Girl in forum Other Programming Languages
    Replies: 3
    Last Post: April 2nd, 2012, 10:43 AM
  5. Javascript/JQuery question
    By Charlie in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 5th, 2010, 09:39 AM

Tags for this Thread