Jump to content

Help with conditionals


matthewordie
 Share

Recommended Posts

I'm trying to set it up where if you press button A, a pop up window opens for that picture. If you press button B. That picture opens instead. My problem is I don't know how to setup a condition for this to happen. I'm familiar with the if else statement, possibly even an arrary for this? Anyways, could I use the buttons class as the variable? How would I do this?

Link to comment
Share on other sites

No need for an array, but i'm unsure on what you mean by "button A". Is it a command button on the page? Or are you talking about the A key on the keyboard? Either is possible very simply =)
I mean just a button on my page. I'm looking to know how to use either the button's class or id in my conditional statement. Here's kinda what I got:
function PopWindow() {	if (condition) {		window.open("itempage01.html", "myWindow", "status=1, height=450, width=550, resizable=0");	}	else if (condition) {		window.open("itempage02.html", "myWindow", "status=1, height=450, width=550, resizable=0");	}

My problem is I'm not sure on the syntax for my conditional. ButtonA on my page has a class of BtnA. How would I use that in the condition?

Link to comment
Share on other sites

If you've got the choice, go for id. Then you can use the relatively simple:document.getElementById('Object_ID');to access it.
Thanks alot thats right on the track I was looking for. Here's what I got now...
function PopWindow() {	if (document.getElementById('btn1')) {		window.open("itempage01.html", "myWindow", "status=1, height=450, width=550, resizable=0");	}	else if (document.getElementById('btn2')) {		window.open("itempage02.html", "myWindow", "status=1, height=450, width=550, resizable=0");	}	else {	 	}}

Right now both buttons are popping up only "itempage01.html". Am I missing something in my condition?

Link to comment
Share on other sites

Yes, your code is just saying "if the button is on the page... carry out... "i'm guessing you've got some button on the page with code:... onclick="PopWindow()" .... You need something more like this:... onclick="PopWindow(1)" ...on the first button, and:... onclick="PopWindow(2)" ... on the second. Then your function code would look like:

function PopWindow( num ) {	if (num == 1) {		window.open("itempage01.html", "myWindow", "status=1, height=450, width=550, resizable=0");	}	else if (num == 2) {		window.open("itempage02.html", "myWindow", "status=1, height=450, width=550, resizable=0");	}	else {		}}

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...