473,796 Members | 2,703 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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"+card s[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=d ocument.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 1818
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="javas cript">
function updateTries(n){
var o=document.getE lementById("tri es");
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"updat es 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.score Form.scoreBox.v alue = trys"

Mike

Feb 1 '07 #4

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

Similar topics

3
12883
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 variable when the city Coeur d'Alene was read. It appears that javascript is intrepreting the quote to end after d'. I've tried reversing the quotes (instead of " ' ' ", ' " " ') and using the javascript escape command. Neither worked. Please help!...
14
2621
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 (that part's not here -- spotlighting the problem code): --------BEGIN CODE PAGE------------ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
0
1227
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 datepicker control to the toolbox, it just shows a yellow dot and thats it. What happened to the text??? Earl
7
8363
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 the interface has been generated. The interface language is dynamically loaded and the text is displayed using Java's <fmttags. How can I make the Javascript alerts, etc. also change their display language dynamically? Is it possible in...
1
25702
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 bad breath)? Scope describes the context in which a variable can be used. For example, if a variable's scope is a certain function, then that variable can only be used in that function. If you were to try to access that variable anywhere else in...
1
4225
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 aligned to the top, along with the slideshow and link buttons, you have to scroll down to see the text - how can I make IE6 display correctly? http://geekarama.co.uk/new_home.html here is the code for new_home.html and following that the CSS...
9
2298
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." 4. Display last modified date of doc. Here is my attempt. What a headache :-(
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9531
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3735
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.