Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy how do i make the button submit only five times

    i tried to fix it with with the refresh() function but i dont know whats wrong i if u knowq what to do to make the guess button submit only five times please let me know
    heres the JS-

    <SCRIPT language=JavaScript>
    <!-- Begin
    var js_mult1=3141
    var js_mult2=5821
    var js_m1=100000000
    var js_m2=10000
    var js_iseed=0
    var js_iseed1=0
    var js_iseed2=0
    function random() {
    if (js_iseed == 0) {
    now = new Date()
    js_iseed = now.getHours() + now.getMinutes() * 60 + now.getSeconds() * 3600
    }
    js_iseed1 = js_iseed / js_m2
    js_iseed2 = js_iseed % js_m2
    var tmp = (((js_iseed2 * js_mult1 + js_iseed1 * js_mult2) % js_m2) *
    js_m2 + (js_iseed2 * js_mult2)) % js_m1
    js_iseed = (tmp + 1) % js_m1
    return (Math.floor((js_iseed/js_m1) * 100))
    }
    var nGuesses = 0
    function GuessNum() {
    var response
    var num = parseInt(document.forms[0].guess.value)
    document.forms[0].guess.value = num
    nGuesses++
    response = ""
    if (num < myNumber) response = response + "Higher!"
    if (num > myNumber) response = response + "Lower!"
    if (num == myNumber) {
    respone = "Correct!";
    alert ("Winner!! Congrats Click ok For your prize...")
    alert ("CzoneName: PW:")
    alert ("Remember only one prize per week....");
    }
    document.forms[1].result.value=response
    document.forms[1].guesses.value=nGuesses
    document.forms[0].guess.focus()
    document.forms[0].guess.select()
    return true
    }
    function GiveUp() {
    var response
    nGuesses = 0
    alert("Try it again you'll get it....")
    alert("Eventually????") ;
    }
    function refresh()
    {
    if (nGuesses<="5")
    {GuessNum()
    return true
    }
    else
    {alert('You have run out of chances'); window.location="http://www.freewebs.com/ctp/guess.htm"}
    }
    </SCRIPT>
    // End -->
    </SCRIPT>

    <META content="MSHTML 6.00.2900.2523" name=GENERATOR></HEAD>
    <BODY vLink=#0000ff bgColor=#ffffff onload=document.forms[0].guess.focus();document.forms[0].guess.select();refresh()/>
    <CENTER><BR>
    <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
    <TBODY>
    <TR>
    <TD align=middle width="99%"><BASEFONT><FONT size=6></B></FONT>
    <TABLE cellSpacing=0 cellPadding=3 width=486 border=0>
    <TBODY>
    <TR>
    <TD><FONT face=helvetica,arial,geneva></FONT></TD></TR></TBODY></TABLE>
    <CENTER>
    <H2>&nbsp;</H2>
    <P><FONT size=2><B>The object of this game is to guess the same number that the computer has guessed. The number will range from 1 to 100.
    <P></B></FONT>
    <SCRIPT>
    myNumber = random();
    nGuesses = 0
    </SCRIPT>

    <FORM onsubmit="GuessNum(); refresh(); return false">Your Guess: <INPUT size=5 name=guess> <INPUT type=button value=" Guess... " onclick="GuessNum(); refresh();"> <INPUT onclick=GiveUp(); type=button value=" GiveUp "> </FORM>
    <FORM>
    <CENTER>#-Guesses: <INPUT size=3 name=guesses> INFO: <INPUT size=10 name=result> </CENTER></FORM>

  • #2
    New Coder
    Join Date
    Nov 2004
    Location
    wisconsin
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i might be wrong but i dont think there is a size attribute on input items. make a function and a variable named addguess in your code. theres the function
    Code:
    function addguess(){
    if (addguess >5){
    (addguess + 1)}
    else{
    document.write("You have already guessed 5 times");}
    that should work but i did it in a hurry
    Can you commentate bowling?

  • #3
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Cool

    i got it to work from another person but thanks
    Last edited by tamaisk; 01-09-2005 at 11:40 PM.

  • #4
    WA
    WA is offline
    Administrator
    Join Date
    Mar 2002
    Posts
    2,596
    Thanks
    2
    Thanked 19 Times in 18 Posts
    BTW, please do not post the same question more than once as you have (two duplicate threads), per our rules. Closing this thread.
    - George
    - JavaScript Kit- JavaScript tutorials and 400+ scripts!
    - JavaScript Reference- JavaScript reference you can relate to.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •