Beginner Needing Help!!

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TempMan

    #1

    Beginner Needing Help!!

    I want this text field to always display a number variable.
    The variable "num" is defined in the head, how can I get a text box to
    display this varibale??

    <input name="Balance" type="text" value="num" size="8" maxlength="8">

    Cheers
  • Stuart Palmer

    #2
    Re: Beginner Needing Help!!

    <script language="javas cript">
    var num = 5; // 5 or variable
    </script>
    <body onload="javascr ipt:document.my form.Balance.va lue = num;">
    <form name="myform">
    <input name="Balance" type="text" value="" size="8" maxlength="8">
    </form>
    </body>


    This is how i'd do it.

    Don't forget JS is case sensitive.

    Stu

    "TempMan" <dotau@tpg.com. au> wrote in message
    news:140d9687.0 309022154.3d955 5b7@posting.goo gle.com...[color=blue]
    > I want this text field to always display a number variable.
    > The variable "num" is defined in the head, how can I get a text box to
    > display this varibale??
    >
    > <input name="Balance" type="text" value="num" size="8" maxlength="8">
    >
    > Cheers[/color]


    Comment

    • Nobody

      #3
      Re: Beginner Needing Help!!

      Leave off the javascript: prefix and that will do fine.

      "Stuart Palmer" <tryandspamme@y oucant.com> wrote in message
      news:8Ff5b.629$ 8_5.110061@news fep2-gui.server.ntli .net...
      | <script language="javas cript">
      | var num = 5; // 5 or variable
      | </script>
      | <body onload="javascr ipt:document.my form.Balance.va lue = num;">
      | <form name="myform">
      | <input name="Balance" type="text" value="" size="8" maxlength="8">
      | </form>
      | </body>
      |
      |
      | This is how i'd do it.
      |
      | Don't forget JS is case sensitive.
      |
      | Stu
      |
      | "TempMan" <dotau@tpg.com. au> wrote in message
      | news:140d9687.0 309022154.3d955 5b7@posting.goo gle.com...
      | > I want this text field to always display a number variable.
      | > The variable "num" is defined in the head, how can I get a text box to
      | > display this varibale??
      | >
      | > <input name="Balance" type="text" value="num" size="8" maxlength="8">
      | >
      | > Cheers
      |
      |


      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Beginner Needing Help!!

        dotau@tpg.com.a u (TempMan) writes:
        [color=blue]
        > I want this text field to always display a number variable.
        > The variable "num" is defined in the head, how can I get a text box to
        > display this varibale??
        >
        > <input name="Balance" type="text" value="num" size="8" maxlength="8">[/color]

        You have to add the value using Javascript. The code for this is:

        document.forms['formName'].elements['Balance'].value = num;

        You can either use this code anywhere after the element tag:

        <script type="text/javascript">
        document.forms['formName'].elements['Balance'].value = num;
        </script>

        (Remember to use the "type" attribute, not the "language" attribute
        on the script tag, if writing HTML 4 or later).

        Or you can add it using the documents onload handler:

        <body
        onload="documen t.forms['formName'].elements['Balance'].value = num;">

        (don't put "javascript :" in front of HTML event handlers, it is not
        a link, so the javascript: pseudo protocol doesn't apply).

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • ::::x::::

          #5
          Re: Beginner Needing Help!!

          None of these work.
          It's a game, the user opens the page then clicks on the amount they wish to
          deposit.
          I need the text box to display the amount in their bank. It will be $0 when
          the page loads and them change as they play the game..

          Below is the full code (which isn't bug free yet..)


          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          <html>
          <head>
          <title>:: Tafe - Roll a Dice ::</title>
          <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

          <!-- Casion Emulator -->

          <script language="JavaS cript" type="text/javascript">
          <!-- Hide me from old browsers

          // Gets bg colour based on time
          time = new Date()
          if (time.getHours( ) <= 12) {
          document.bgColo r = "CC0000" }
          else {
          document.bgColo r = "339900"
          }

          // Casion Images
          function pic(){
          pic_array=new Array()
          pic_array[1]="images/pic01.gif"
          pic_array[2]="images/pic02.gif"
          pic_array[3]="images/pic03.gif"
          pic_array[4]="images/pic04.gif"
          pic_array[5]="images/pic05.gif"
          pic_array[6]="images/pic06.gif"

          picnum=Math.flo or(Math.random( )*pic_array.len gth)
          if (picnum==0)
          picnum=1
          document.write( '<center><img src="'+pic_arra y[picnum]+'"
          border=0></center><br>')
          }
          pic()
          document.write( "<hr>")
          // Game starts here

          var bank = 0
          var betbank = 0
          var money_in = 0
          var money_out = 0
          var bet_out = ""
          var bet_in = 0
          var theroll = 0
          var win = 0
          var rollnum = 0
          var dep_clickcount = 0
          var gamble_clickcou nt = 0
          var pick_clickcount = 0
          var roll_clickcount = 0

          // Prompt for deposit
          function deposit(money_i n) {

          if ( dep_clickcount == 0 ) {
          alert( "You Deposited $" + money_in )
          bank = bank + money_in
          dep_clickcount+ +
          }
          else { alert("You can only make one deposit, hit 'refresh' if you wish to
          change your deposit")
          }
          }

          // Prompt for money on bet
          function gamble(money_ou t)
          {
          if ( bank != 0 && bank >= money_out ) {
          gamble_clickcou nt++
          bank = bank - money_out
          betbank = betbank + money_out
          alert("$" + betbank + " placed on bet. $" + bank + " left in the bank") }
          else {
          alert("Balance: $" + bank ) }
          }

          // Prompt for bet
          function bet(bet_in)
          {
          if ( bet_in == 1 ) {
          bet_out = "1 to 4" }
          else {
          if ( bet_in == 2 ) {
          bet_out = "5 to 8" }
          else {
          bet_out = "9 to 12" }
          }

          if ( pick_clickcount == 0 && dep_clickcount == 1 && gamble_clickcou nt >=
          1 ) {
          alert("You Picked " + bet_out)
          pick_clickcount ++
          }
          else {
          if ( dep_clickcount == 0 ) {
          alert("You must deposit money first") }
          else { if ( gamble_clickcou nt == 0 ) {
          alert("You must bet first") }
          else { alert("You have already picked")
          }
          }
          }

          }

          // Rolls the dice

          function get_random()
          {
          var ranNum= Math.round(Math .random()*11);
          return ranNum;
          }

          function roll()
          {
          if ( pick_clickcount == 1 && dep_clickcount == 1 && roll_clickcount == 0 &&
          bank != 0 ) {
          alert("You are betting $" + betbank + " on " + bet_out )

          theroll = get_random();

          dicenum = new Array(11)
          dicenum[0]=1;
          dicenum[1]=2;
          dicenum[2]=3;
          dicenum[3]=4;
          dicenum[4]=5;
          dicenum[5]=6;
          dicenum[6]=7;
          dicenum[7]=8;
          dicenum[8]=9;
          dicenum[9]=10;
          dicenum[10]=11;
          dicenum[11]=12;

          rollnum = dicenum[theroll]
          alert("Roll: " + rollnum)

          roll_clickcount = 0
          }
          else {
          if ( dep_clickcount == 0 ) {
          alert("You must deposit money first")
          }
          else {
          if ( pick_clickcount == 0 ) {
          alert("You must bet first")
          }
          else {
          if ( roll_clickcount == 1 ){
          alert("You have already rolled")
          }
          else {
          if ( bank == 0 && roll_clickcount == 0 ){
          alert("Game Over")
          }
          else {
          if ( bank == 0 ){
          alert("Last Go")
          }
          else { alert("Place another bet") }
          }
          }
          }
          }
          }

          if ( bet_in == 1 && rollnum >= 1 && rollnum <= 4 ) {
          bank = bank + ( betbank * 2 )
          win = betbank * 2
          alert( "You won: $" + win )
          alert( "1 Bank $" + bank ) //debugging
          win = 0 }
          else {
          if ( bet_in == 2 && rollnum >= 5 && rollnum <= 8 ) {
          bank = bank + ( betbank * 2 )
          win = betbank * 2
          alert( "You won: $" + win )
          alert( "2 Bank $" + bank ) //debugging
          win = 0
          betbank = 0
          pick_clickcount = 0
          roll_clickcount = 0 }
          else {
          if ( bet_in == 3 && rollnum >= 9 && rollnum <= 12 ) {
          bank = bank + ( betbank * 2 )
          win = betbank * 2
          alert( "You won: $" + win )
          alert( "3 Bank $" + bank ) //debugging
          win = 0
          betbank = 0
          pick_clickcount = 0
          roll_clickcount = 0 }
          else {
          alert( "You lost: $" + betbank )
          alert( "Bank $" + bank ) //debugging
          betbank = 0
          win = 0
          pick_clickcount = 0
          roll_clickcount = 0
          }
          }
          }
          }
          // end hide -->
          </script>
          </head>
          <body link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF"
          onload="documen t.bal.Balance.v alue = bank;">
          Click the amout you wish to deposit
          <br>
          <IMG onmouseover="wi ndow.status='$5 00'" onclick="deposi t(500)"
          onmouseout="win dow.status='';r eturn true" height=75 src="images/0500.gif"
          width=200>
          <IMG onmouseover="wi ndow.status='$6 00'" onclick="deposi t(600)"
          onmouseout="win dow.status='';r eturn true" height=75 src="images/0600.gif"
          width=200>
          <IMG onmouseover="wi ndow.status='$7 00'" onclick="deposi t(700)"
          onmouseout="win dow.status='';r eturn true" height=75 src="images/0700.gif"
          width=200><br>
          <IMG onmouseover="wi ndow.status='$8 00'" onclick="deposi t(800)"
          onmouseout="win dow.status='';r eturn true" height=75 src="images/0800.gif"
          width=200>
          <IMG onmouseover="wi ndow.status='$9 00'" onclick="deposi t(900)"
          onmouseout="win dow.status='';r eturn true" height=75 src="images/0900.gif"
          width=200>
          <IMG onmouseover="wi ndow.status='$1 000'" onclick="deposi t(1000)"
          onmouseout="win dow.status='';r eturn true" height=75 src="images/1000.gif"
          width=200>
          <br>
          <hr>
          <br>
          <form name="bal">
          Current Balance: $<input name="Balance" type="text" value="" size="8"
          maxlength="8">
          </form>
          <form>
          Place Money On Bet:
          <input type="button" name="Submit00" value="$100" onClick="gamble (100)">
          <input type="button" name="Submit01" value="$200" onClick="gamble (200)">
          </form>
          <form>
          Place Bet:
          <input type="button" name="Submit02" value="1 to 4" onClick="bet(1) ">
          <input type="button" name="Submit03" value="5 to 8" onClick="bet(2) ">
          <input type="button" name="Submit03" value="9 to 12" onClick="bet(3) ">
          </form>
          <form>
          <input type="button" name="Submit04" value="Roll Dice" onClick="roll() ">
          </form>
          <br>
          <p align="center"> <a href="casino.ht ml"><font size="5" face="Comic Sans
          MS">Return to casino</font></a></p>
          </body>
          </html>



          Comment

          Working...