473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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
Jul 20 '05 #1
4 1727
<script language="javascript">
var num = 5; // 5 or variable
</script>
<body onload="javascript:document.myform.Balance.value = 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" <do***@tpg.com.au> wrote in message
news:14**************************@posting.google.c om...
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

Jul 20 '05 #2
Leave off the javascript: prefix and that will do fine.

"Stuart Palmer" <tr**********@youcant.com> wrote in message
news:8F******************@newsfep2-gui.server.ntli.net...
| <script language="javascript">
| var num = 5; // 5 or variable
| </script>
| <body onload="javascript:document.myform.Balance.value = 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" <do***@tpg.com.au> wrote in message
| news:14**************************@posting.google.c om...
| > 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
|
|
Jul 20 '05 #3
do***@tpg.com.au (TempMan) writes:
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">


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="document.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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
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="JavaScript" type="text/javascript">
<!-- Hide me from old browsers

// Gets bg colour based on time
time = new Date()
if (time.getHours() <= 12) {
document.bgColor = "CC0000" }
else {
document.bgColor = "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.floor(Math.random()*pic_array.length)
if (picnum==0)
picnum=1
document.write('<center><img src="'+pic_array[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_clickcount = 0
var pick_clickcount = 0
var roll_clickcount = 0

// Prompt for deposit
function deposit(money_in) {

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_out)
{
if ( bank != 0 && bank >= money_out ) {
gamble_clickcount++
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_clickcount >=
1 ) {
alert("You Picked " + bet_out)
pick_clickcount++
}
else {
if ( dep_clickcount == 0 ) {
alert("You must deposit money first") }
else { if ( gamble_clickcount == 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="document.bal.Balance.value = bank;">
Click the amout you wish to deposit
<br>
<IMG onmouseover="window.status='$500'" onclick="deposit(500)"
onmouseout="window.status='';return true" height=75 src="images/0500.gif"
width=200>
<IMG onmouseover="window.status='$600'" onclick="deposit(600)"
onmouseout="window.status='';return true" height=75 src="images/0600.gif"
width=200>
<IMG onmouseover="window.status='$700'" onclick="deposit(700)"
onmouseout="window.status='';return true" height=75 src="images/0700.gif"
width=200><br>
<IMG onmouseover="window.status='$800'" onclick="deposit(800)"
onmouseout="window.status='';return true" height=75 src="images/0800.gif"
width=200>
<IMG onmouseover="window.status='$900'" onclick="deposit(900)"
onmouseout="window.status='';return true" height=75 src="images/0900.gif"
width=200>
<IMG onmouseover="window.status='$1000'" onclick="deposit(1000)"
onmouseout="window.status='';return 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.html"><font size="5" face="Comic Sans
MS">Return to casino</font></a></p>
</body>
</html>

Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ::::x:::: | last post by:
Hi All, below is come code I'm writing for an assignment, and I'm stuck. What I want to happen: page load, user click on money money = bank bank is displayed in a text box I can get the bank...
7
by: BobJohnson | last post by:
Just started learning C++ and I need some help with my homework, shouldn't take long for people around here. I need to create a simple money calculator but I don't know how to make the output...
1
by: Hought, Todd | last post by:
Hi all, trying to run a query against a table, to pull the date out, and order it. problem is, the date is stored in character (string) format, not as an actual timestamp, so parsing it back into...
1
by: Simon Matthews | last post by:
Hope someone can help an Access beginner! I've just started keeping my surgical logbook on access and it's a simple flat-file affair. I have created several queries that will list cases...
3
by: Chung Hang Shum | last post by:
I'm a beginner in ASP.Net. I'd wroten mange asp code before and now I need to transfer them from asp to asp.Net. In classical ASP you can write code like this: <% If strRequest = "ConfirmPasswd"...
5
by: Jozef | last post by:
Hello, I have done a little "old" ASP work along with some javascript. I'm currently getting into ASP.net and would like to step up my game overall with regard to Web Development. I was...
7
by: try2nd | last post by:
I have console application where i can read line by line from a .txt file and save it to a different file name in .txt format as well. Here's the basic code: using System.IO namespace Dim fs As...
1
by: hl | last post by:
Hi, I'm a beginner and need a little help with getting data back from a web service. I am using VB.Net and have added a web reference to a Wsdl that was provided to me. My reference.vb file...
4
by: chris19845 | last post by:
Hi there, I am a complete beginner so apologies if I make not a lot of sense. What I am trying to do is write a simple class, it has a class array variable named test of type String, ie private...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.