Hello and welcome to the Webmasters Forums!. This is the best place to get webmasters resources for free. Get $2 for free today, read more - Make your payment today. Download premium and professional templates for free. Get free web hosting without ads, read more. You can get lot more by simply join with this forum. To gain full access to the forums you must sign up for a free account.


Post Reply  Post Thread 

Using Buttons for JavaScripts

Post Bank
Posting Manager
******

Posts: 995
Group: Forum Team
Joined: Sep 2006
Status: Online
Make money from now. You can make money just for posting on this forum. Every discussions on this community gives you more money. $2 minimum payout. So get your payment today, SignIn with this forum.

Signin to Remove this Post

ivenms
Administrator
*******


Posts: 2,179
Group: Administrators
Joined: Sep 2006
Status: Offline
Reputation: 14
Points: 4389 (Donate)
Post: #1

Smile Using Buttons for JavaScripts


To write scripts using buttons, we will first need to know how to place a button on the page. To do this, you will need to use the <FORM> tags around the button tag. Here is an example of the HTML that will place a button on the page:

<FORM>
<INPUT type="button" value="Click Me" name="button1">
</FORM>

This will place a button on your page, but if you click on it nothing will happen....


Here is what all this means:

<FORM>
This creates a form so we can use a button.

<INPUT>
This tag allows us to create an input area of some kind.

type="button"
This command declares our input area to be a button.

value="Click Me"
This will be the text people will see on the button. Write whatever you want your visitors to see.

name="button1"
You can give the button a name for future reference and possibly for use in a script.

Now, I know you don't just want to make buttons that don't do anything, so let's look at a javascript command that will make the browser do something when a viewer clicks it:

onClick="javascript commands"

Just place this command inside the INPUT tag you created the button with, like this:

<INPUT type="button" value="Click Me" name="button1" onClick=" ">

Now, if you read the last section, you saw how to add text to the status bar using the onMouseover command. Well, you can also use a button to do this!

<FORM>
<INPUT type="button" value="See Some Text" name="button2" onClick="window.status='You clicked the button!'; return true">
</FORM>


You can also allow your viewers to change the background color of your page. Just use the following command, rather than the window.status command:

document.bgColor='color'

Just insert this as your instructions for the onClick command, like this:

<FORM>
<INPUT type="button" value="Change to Yellow!" name="button3" onClick="document.bgColor='yellow'">
</FORM>


You can add as many of these buttons as you like, just be sure they have the option to change back to the original color. The next script will give you three choices: yellow, red, and original color.

<FORM>
<INPUT type="button" value="Change to Yellow!" name="button3" onClick="document.bgColor='yellow'"> <br>
<INPUT type="button" value="Change to Red!" name="button4" onClick="document.bgColor='red'"> <br>
<INPUT type="button" value="Change back!" name="button5" onClick="document.bgColor='white'"> </FORM>


The last script we will do in this section will allow you to use your button as a link. It's pretty fun to use every now and then. Just use the following command in your onClick command:

window.location='url'

Here is a script that will send you to a page I made just for this example:

<FORM>
<INPUT type="button" value="Go to my other Page!" name="button6" onClick="window.location='http://www.pageresource.com/jscript/newpage.htm'">
</FORM>


Read: General Rules & Policies before posting.
Make Money By Posting | Earning and Exchanging Points | Add Your Links
15-09-2006 03:01 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
Smile Foward and Back Buttons ivenms 0 641 15-09-2006 03:02 AM
Last Post: ivenms

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites
Rate This Thread:

Forum Jump:

Sign In to Remove Ads

Download 1000's of web templates. Unlimited access!
World's Best Web Hosting
Website of the Month

Create-a-Page for Free
SOTM June 2008


Accepting Submissions
for July 2008
Resources

Recommended Sites:



Visit our Sponsors!

Current time: 29-08-2008, 03:47 PM


Copyright © 2002-2008 MyBB Group
Powered By MyBB