button problem

JavaScript related questions should go here.
Post Reply
Romulas
Posts: 24
Joined: Mon Sep 12, 2011 3:59 am

button problem

Post by Romulas »

hi
I wan't to have a page with 4 buttons, and when i press one of the buttons i want some other things to happen.
I have written some html code for the buttons and some code to check which button i pressed. However when i
test this, it runs and automatically selects and uses the first button on the page.(top left) How can i make this work so that when the page loads, it waits until i press one of the buttons before it does anything else.
I hope this make sense
Thank you for your help

I have just started this there is no code to post
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: button problem

Post by Helx »

Would you be able to elaborate further?
I'm un-sure of your problem.

Are you talking about JavaScript or the 'tabselect'?
Romulas
Posts: 24
Joined: Mon Sep 12, 2011 3:59 am

Re: button problem

Post by Romulas »

hi
I have done a little research on the problem, and i found that this requires javascript to work. I did'nt know
that when i posted this article. However, i did find out about the html 'onClick' event, is it possible to use that. If so,
could you elaborate on how could this be done.

I want to have 4 buttons on the page when it loads. Then depending on which button i press
it should continue because i want the name of the button to also be the name of the file that will be opened
thats why i want the page to stop once it loads the 4 buttons.

Hope all this helps
Thank you
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: button problem

Post by Helx »

Let me get this straight:
You want 4 buttons on a blank(isn?) page which, when pressed load different files?

This is not too difficult, but we'll keep it basic.
We'll use jQuery.

You need to start off by (obviously) making your buttons. Give each <button> an "onClick" tag like so:

[syntax=xhtml]<button onClick="">file 1</button>
<button onClick="">file 2</button>
<button onClick="">file 3</button>
<button onClick="">file 4</button>[/syntax]
You then need to put a random DIV with the ID "someDiv" below them, spanning the whole page. Your code should look like so:

[syntax=xhtml]<button onClick="">file 1</button>
<button onClick="">file 2</button>
<button onClick="">file 3</button>
<button onClick="">file 4</button>

<div style="width:100%;height:100%" id="someDiv"></div>[/syntax]
Then, with each button's "onClick", you need to insert the following code like so (substitute your own file names):

[syntax=xhtml]<button onClick="$('#someDiv').load('file1.html');">file 1</button>
<button onClick="$('#someDiv').load('file1.jpg');">file 2</button>
<button onClick="$('#someDiv').load('path/to/file3.html');">file 3</button>
<button onClick="$('#someDiv').load('goGoJuice.php');">file 4</button>

<div style="width:100%;height:100%" id="someDiv"></div>[/syntax]
If you wanted to use the onClick with a class instead of a div, you can change "#someDiv" to ".someClass".

Note that this is NOT good for SEO. Search engines never build JavaScript (well, Google does, but Google never 'clicks' buttons).

I hope this helps!
If you have any further questions, please ask (I did sorta give you the whole code :s )

Moved to JavaScript section.
Romulas
Posts: 24
Joined: Mon Sep 12, 2011 3:59 am

Re: button problem

Post by Romulas »

Thank you Helix
I will try this out
ExtremeGaming
Posts: 205
Joined: Mon Jul 09, 2012 11:13 pm

Re: button problem

Post by ExtremeGaming »

Don't forget that you will need to use JQuery for that example.
<?php while(!$succeed = try()); ?>
User avatar
Helx
Posts: 350
Joined: Thu May 17, 2012 6:45 am
Location: Auckland, New Zealand

Re: button problem

Post by Helx »

ExtremeGaming wrote:Don't forget that you will need to use JQuery for that example.


Oops, forgot to mention that :oops:
Thanks for the reminder!
Post Reply