Click to See Complete Forum and Search --> : Buttons


JScriptNewbie
03-07-2003, 08:20 PM
I tried using the script for buttons that they gave me in the book "JavaScript for the World Wide Web", but it didn't work. Does anyone else know how to make buttons? Preferrably buttons that work? The script they gave me made the button, but the button itself didn't work. :confused:

dabush
03-07-2003, 10:00 PM
Well what do you want your button to do?


<html>
<head>
<script type=text/javascript language=JavaScript>
<!--
function onClickButton()
{
// Do this stuff when someone clicks the button
}
// -->
</script>
</head>
<body>
<form name=myform>
<input name=mybutton type=button value="Click Me!" onClick="onClickButton();">
</form>
</body>
</html>

JScriptNewbie
03-07-2003, 10:20 PM
This is the script the book gave me:

<FORM>
<center>
<INPUT TYPE=BUTTON VALUE="NEXT"
onClick="saySomething('blah blah blah')">
</FORM>

It didn't work.

I'll try the other script though.

JScriptNewbie
03-07-2003, 10:26 PM
dabush's script was more like what I wanted... see what I want is for this to happen when the button is clicked: document.write("text"). However, I tried adding this in to dabush's script, but nothing happened when I clicked the button.

JScriptNewbie
03-07-2003, 10:38 PM
My buttons never ever do anything no matter what I try! *cries* :(

zapdos900
03-08-2003, 06:45 AM
Hey guys check this button out!


<html>
<head>
<script type=text/javascript language=JavaScript>
<!--
function onClickButton()
{
alert('Text')
}
// -->
</script>
</head>
<body>
<form name=myform>
<input name=mybutton type=button value="Click Me!" onClick="onClickButton();">
</form>
</body>
</html>

JScriptNewbie
03-09-2003, 06:25 PM
I've gotten plenty of JavaScript to work...just not buttons. I want my button to make more text appear on the page. Not in a little box, like with the last thing (see my select-and-go post if you're wondering what that was), but actual text text. Is that even possible, or do buttons not work that way???

pyro
03-09-2003, 06:59 PM
Please try this code:

<html>
<head>
<script language="javascript" type="text/javascript">
function addText()
{
document.getElementById("mydiv").innerHTML = "This is some text";
}
</script>
<body>
<form name="myform">
<input type="button" name="mybutton" value="Click me" onClick="addText()">
</form>
<div id="mydiv"></div>
</body>
</html>

Nedals
03-09-2003, 09:09 PM
My buttons never ever do anything no matter what I try! *cries*It's not the button that's the problem, it's what you are asking (or in your case, not asking) the button to do. A button by itself does NOTHING but look nice. You will notice that the above posts all have this in common...

<input type="button" value="Click me" onClick="JSfunction()">
The onClick (activated when you click the button) is used to CALL a Javascript function. It's this function that does the work, not the button.

The addText() function in Pyro's post will do what you want.

JScriptNewbie
03-10-2003, 07:41 PM
YAY! pyro's code worked! *does a happy dance* :D

pyro
03-10-2003, 07:49 PM
Glad to hear you got it... :D