473,320 Members | 1,916 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,320 software developers and data experts.

Displaying Javascript variable in text box.

Hi.

I'm creating a simple memory game in which the user has to make pairs
from cards. I would like the user to see the variable "trys" (the
score) update on the page dynamically (in a text box would be great).
I can do this by showing a msgbox every time try increments but this
is annoying to use. I have been trying for hours to get this to work,
using innerhtml.

function turnOver(e)
{
if (matchCount<8 & !matched[e.name]) //If the game hasn't finished
and the chosen card isn't already matched then...
{

if (clicked<1) //If this is the first card
{
firstCard=e; //grab first card object
pair=cards[firstCard.name]; //get first pair number from cards
array
e.src=document.images["load"+pair].src; //flip over first card
}

else //If one card is already chosen
{
e.src=document.images["load"+cards[e.name]].src; //flip over second
card

if (pair!==cards[e.name]) //If cards aren't the same then...
{
trys++ //UPDATE THE SCORE ON THE PAGE HERE
alert("No Match! " + trys + " trys so far")
firstCard.src=document.images["load0"].src; //flip first card back
e.src=document.images["load0"].src; //flip second card back
}

else //If cards are the same then...
{
//Record matched cards and increase matchCount
matched[firstCard.name]=true;
matched[e.name]=true;
matchCount++;
trys++ //UPDATE THE SCORE ON THE PAGE HERE
}
}

Any help would be greatly appreciated.

Mike

Feb 1 '07 #1
3 1798
dd
On Feb 1, 8:42 pm, mbayn...@gmail.com wrote:
I have been trying for hours to get this to work,
using innerhtml.
Can you show the code that tried to do innerHTML?
I wonder whether you did all lower case innerhtml
instead of innerHTML. This is an example of writing
to innerHTML:

Current Tries: <div id="tries">0</div>

<script language="javascript">
function updateTries(n){
var o=document.getElementById("tries");
if(o){
o.innerHTML=n;
}
}

Feb 1 '07 #2
Hey. Thanks for your quick reply. The inner"html" was just a typo. I
wish that was my mistake. I have been looking at examples on w3
schools but they don't seem to have anything similar.
All I want to do is display the variable "trys" on the page and when
"trys"updates so too does the text on the page. It sounds easy but
has taken up most of my day!

Thanks

Mike
Feb 1 '07 #3
Thanks for the help. It was much easier than I thought

"document.scoreForm.scoreBox.value = trys"

Mike

Feb 1 '07 #4

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

Similar topics

3
by: Jeanne | last post by:
I am working on a cgi script that is suppose to pop-up a javascript box from the following perl variables:$TodayDate, $LinkCity, $LinkState. I recently encountered a problem with the $LinkCity...
14
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file...
0
by: Earl Teigrob | last post by:
I can create a new custom control (and not change it) and add it to the toolbox and drag it onto the disign screen and it works just fine, displaying the text . However, when I add the following...
7
by: swethasivaram | last post by:
Hello I have a Java-based web application whose interface can be in multiple languages. My requirement is that the javascript alerts that I display should be displayed in the language in which...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
9
by: LayneMitch via WebmasterKB.com | last post by:
Hello. Got another one for you folks. I'm working on this problem that wants me to 1. Prompt for name 2. Use pop-up box with name 3. Display current date on page in format "October 30, 2000."...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.