in JavaScript by
How To Add Buttons In Javascript?

1 Answer

0 votes
The most basic and ancient use of buttons are the "submit" and "clear", which appear slightly before the Pleistocene period. Notice when the "GO!" button is pressed it submits itself to itself and appends the name in the URL.

<form action="" name="buttonsGalore" method="get">

Your Name: <input type="text" name="mytext" />

<br />

<input type="submit" value="GO!" />

<input type="reset" value="Clear All" />


Another useful approach is to set the "type" to "button" and use the "onclick" event.

<script type="text/javascript">

function displayHero(button) {

alert("Your hero is \""+button.value+"\".");



<form action="" name="buttonsGalore" method="get">

<fieldset style="margin: 1em; text-align: center;">

<legend>Select a Hero</legend>

<input type="button" value="Agamemnon" onclick="displayHero(this)" />

<input type="button" value="Achilles" onclick="displayHero(this)" />

<input type="button" value="Hector" onclick="displayHero(this)" />

<div style="height: 1em;" />



Related questions

0 votes
asked Mar 2, 2020 in JAVA by rahuljain1
0 votes
asked Jun 9, 2022 in JavaScript by sharadyadav1986
0 votes
asked Jun 8, 2022 in JavaScript by sharadyadav1986