Jump to content

On Click: If/then


Psy
 Share

Recommended Posts

Fist off, I'm new to JavaScript, but I have done HTML/CSS for a while. I am creating a random Pokémon generator, and I'm trying to make a menu with a JS effect. The links are supposed to go to a certain part of my site, but if the checkbox on the right is selected, it it supposed to go to a different set of links. Like I said, I'm new to JS and would like it if someone could tell me what I'm doing wrong here.The HTML page (relevant part below)

	<div id="navbar"><ul><li style="margin: 0 8px; cursor: default;">Generate: </li><li><a href="http://randompokemon.50webs.com/pokemon/" id="any">Any Pokémon</a></li><li><a href="http://randompokemon.50webs.com/oupokemon/" id="ou">OU Pokémon</a></li><li style="margin: 0 10px; font-size: x-small;"><input type="checkbox" id="nature" onclick="changeurl()" value="With natures?" style="vertical-align:middle" /><label for="nature">  With natures?</label></li></ul>	</div>

JS file:

function changeurl() {if (document.getElementById("nature").checked == true){document.getElementById('any').href="http://randompokemon.50webs.com/pokenature/";document.getElementById('ou').href="http://randompokemon.50webs.com/ounature/";}else {document.getElementById('any').href="http://randompokemon.50webs.com/pokemon/";document.getElementById('ou').href="http://randompokemon.50webs.com/oupokemon/";}}

Link to comment
Share on other sites

Thanks, I changed that, but it still doesn't seem to work. I feel like the following is a problem, but because I'm so new to JavaScript, I can't tell:

{  content part 1 { part 2 }   back to part 1  }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...