473,326 Members | 2,081 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,326 software developers and data experts.

html/javascript link code not working no matter how I put it.

tpgames
785 512MB
Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:selectLetter('A')" + document.body.aLink;" >A</a> | 
  2. <a href="javascript:selectLetter('B')" + document.body.aLink;>B</a> 
I've read the JS Bible, JS for the WWW, and Visual JS and have not found the answer to what I'm trying to do. I need the link to access the CSS sheet so that after the link is pressed, it will turn red from blue. The usual
Expand|Select|Wrap|Line Numbers
  1. <body onLoad="function1();">
  2. <script>
  3.     function function1() {
  4.         document.body.aLink = "red";
  5.     }
  6. </script>
  7. <a href="http://www.link.com/"> link.vom (click to turn red)</a>
  8. </body>[color=#000000]
  9. [/color][color=#000000][/color]
that I found, doesn't really do what I want it to do.

Thanks!
Apr 29 '08 #1
16 1682
tpgames
785 512MB
I tried using a DIV tag, but that didn't change a think with the links.
Expand|Select|Wrap|Line Numbers
  1. CSS Sheet has :
  2. div.navLink a:link { color:#0000ff; text-decoration: underline; }
  3. div.navLink a:visited { color:#ff0000; text-decoration: underline; }
  4. div.navLink a:hover { color:#0000ff; font-weight: font-size: 24px;}
  5. div.navLink a:active { color:#0000ff; text-decoration: underline; }
  6.  
  7. The HTML page has:
  8. <div class="navLink"> 
  9.  
That didn't worked.

Link to Full Code.
Apr 29 '08 #2
tpgames
785 512MB
Now that I think about it, I really need the link to reset itself to Blue when the "start game/ reset game" button is pushed.

So, what I really need to accomplish is:
click on blue link, link changes to red.
click on "reset game", link changes back to blue.

I've successfully made regular html links before that changed colours. It amazing that nothing is working here, only because of a silly JS type link.
Apr 30 '08 #3
acoder
16,027 Expert Mod 8TB
Use an onclick to change the colour, e.g.
Expand|Select|Wrap|Line Numbers
  1. onclick="this.style.color='#ff0000'"
link
Apr 30 '08 #4
tpgames
785 512MB
I knew their was something really obvious I forgot to try. Thanks!
Apr 30 '08 #5
tpgames
785 512MB
Okay, if I do offclick to change the color back, it will change it back before It want it too. The reset button doesn't change the links back to blue. What code would cause the reset button to change all the links back to blue?

Is there a onreset code? something like
Expand|Select|Wrap|Line Numbers
  1. onreset="this.style.color='#0000ff'"? 
I know that the above doesn't work, but something like it.
Thanks!
Apr 30 '08 #6
pronerd
392 Expert 256MB
The reset button doesn't change the links back to blue. What code would cause the reset button to change all the links back to blue?
Expand|Select|Wrap|Line Numbers
  1.         <button id="someIdName" onClick="this.style.color='#0000ff';" />
  2.  
Apr 30 '08 #7
tpgames
785 512MB
I'd delete this message if it were allowed.
Apr 30 '08 #8
tpgames
785 512MB
Expand|Select|Wrap|Line Numbers
  1.         <button id="someIdName" onClick="this.style.color='#0000ff';" />
  2.  
This is what I have to cause the click of the letter to change the link to red.
Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:selectLetter('A');" onclick="this.style.color='#ff0000'">A</a> | 
  2. <a href="javascript:selectLetter('B');" onclick="this.style.color='#ff0000'">B</a> | 
  3. <a href="javascript:selectLetter('C');" onclick="this.style.color='#ff0000'">C</a> | 
Where would I put your code to revert all the links back to blue after the person has reset the page?
Apr 30 '08 #9
pronerd
392 Expert 256MB
The reset button doesn't change the links back to blue. What code would cause the reset button to change all the links back to blue?
Where is the HTML for this "reset button" you mentioned before?



Where would I put your code to revert all the links back to blue after the person has reset the page?
Since the question relates to resetting the page it would be more productive to display the code that does this reset
Apr 30 '08 #10
tpgames
785 512MB
Here's the requested code. I took a nap so that I could look at this anew.

Expand|Select|Wrap|Line Numbers
  1. function reset()
  2. {
  3. selectWord();
  4. document.game.usedLetters.value = "";
  5. used_letters = "";
  6. wrong_guesses = 0;
  7. document.hm.src="hmstart.gif";
  8. }
Expand|Select|Wrap|Line Numbers
  1. <body onLoad="reset(); return true;">
  2.  
  3. <snip>
  4. <a href="javascript:selectLetter('C');" onclick="this.style.color='#ff0000'">C</a> | 
  5. <a href="javascript:selectLetter('D');" onclick="this.style.color='#ff0000'">D</a> | 
  6. <snip>
  7.  
  8. <a href="javascript:reset()">Start game / Reset game</a> 
  9.  
I tried adding a function thing that would reset the links to blue, but that didn't work. I'm still trying to understand JS coding language.
Thanks! :D
Apr 30 '08 #11
tpgames
785 512MB
Here is again, the link to the full code. Just view the source code.

Its my version of a hangman game. I'm calling it Evaporating Book.
Apr 30 '08 #12
tpgames
785 512MB
Just to be sure it is understood what I am trying to do:

User: clicks on letter link to guess word.
Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:selectLetter('X');">X</a> | 
  2. <a href="javascript:selectLetter('Y');">Y</a> | 
  3. <a href="javascript:selectLetter('Z');">Z</a> </center> </p>
  4.  
Link changes from blue to red.


User continues clicking on letter links until word guessed.
Links continue to change from blue to red as they are clicked.
User guesses word correctly then click Reset button.
Page resets all forms, so that they can play a brand new game.
Except with the current code, the now red links, stay red. Only a reload of the page will change them to blue.

I want these red links to revert back to the original blue so that the user can reclick them to change them to red as they guess new letters when they start a new game.
Apr 30 '08 #13
tpgames
785 512MB
I find it I totally ignore the reset function and instead put in a reload page, everything resets itself. However, I'm still curious as to how else one would do this.

Here's the code I found that does the trick, but makes my JS reset function useless:
Expand|Select|Wrap|Line Numbers
  1. <input type="button" value="Start game / Reset game" onClick="window.location.reload()">
I've not tested it in IE yet, only FF.
Apr 30 '08 #14
acoder
16,027 Expert Mod 8TB
Rather than reloading the page, get all the links on the page, loop over them and set the colour to blue:
Expand|Select|Wrap|Line Numbers
  1. var links = document.getElementsByTagName("a");
  2. for (i = 0; i < links.length; i++) {
  3.     links[i].style.color = "#0000ff";
  4. }
May 1 '08 #15
tpgames
785 512MB
Thanks! That works. I even got it in the right place too. :D I knew there was a JS way of doing it, besides reloading the entire page. lol
May 1 '08 #16
acoder
16,027 Expert Mod 8TB
You're welcome.

With JavaScript, you can change pretty much anything within the page without reloading.
May 1 '08 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

12
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the...
4
by: cjm | last post by:
I have two problems that I suspect will be bread-and-butter problems for the more experienced guys on here, but I'm not the greatest with js. NB: Code snippets at the bottom The first problem...
1
by: Peter Williams | last post by:
Hello All, I'm a newbie to this ng. I'm posting here because I have a question about debugging some javascript on some pages of my website. Please don't call me a "troll" -- because I'm not one....
11
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or...
16
by: Eric | last post by:
I have a user of a web application written in Java/JSP that is unable to login to the site simply because certain links on the page do not run when they are clicked. Other popups using Javascript...
17
by: =?Utf-8?B?Y2F0aGFyaW51cyB2YW4gZGVyIHdlcmY=?= | last post by:
Hello, I have build a website with approximately 30 html-pages. When I search this website in Google, I see the index.html or home.html on this website, but also other html-pages on this...
3
by: amit | last post by:
Hello group, How can I assign a link with its related elements (as following) to an array element? Assume having a table with several rows and 3 columns. The first column holding some text...
2
by: Aykut Canturk | last post by:
there's an aspnet site. some pages are html and cannot be changed. (no javascript nor links can be changed). these pages have links. for example a.html calls b. html like: <a href="b.html"page...
7
by: imtmub | last post by:
I have a page, Head tag Contains many Scripts and style sheet for Menu and Page. This code working fine and displaying menus and page as i wanted. Check this page for reference....
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...
1
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.