Page 1 of 1

button problem

Posted: Sat Jun 15, 2013 2:54 am
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

Re: button problem

Posted: Sat Jun 15, 2013 5:18 am
by Helx
Would you be able to elaborate further?
I'm un-sure of your problem.

Are you talking about JavaScript or the 'tabselect'?

Re: button problem

Posted: Wed Jun 19, 2013 3:16 am
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

Re: button problem

Posted: Wed Jun 19, 2013 5:33 am
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.

Re: button problem

Posted: Thu Jun 20, 2013 2:35 am
by Romulas
Thank you Helix
I will try this out

Re: button problem

Posted: Thu Jun 20, 2013 4:42 am
by ExtremeGaming
Don't forget that you will need to use JQuery for that example.

Re: button problem

Posted: Thu Jun 20, 2013 5:21 am
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!