In: Computer Science
Hello,
How can we create two buttons in a single page side by side through html?And how can we enter different data for different buttons, so that if i click 1st button it should show specific data and if i click second it should show other data?
1. This uses two different javascript functions which are called from two different button clicks and display data using javascript alert box .
<html>
<head>
<script type="text/javascript">
function firstData()
{
alert("Bhaskar");
return true ;
}
function secondData()
{
alert("Kumar");
return true ;
}
</script>
</head>
<body>
<h1> Welcome </h1>
<button onclick="JavaScript:firstData()"/>First
Data</button>
<button onclick="JavaScript:secondData()"/>Second
Data</button>
</body>
</html>
2. This uses two different javascript functions which are called from two different button clicks and display data within the html body by using the id of areas for display .
<html>
<head>
<script type="text/javascript">
function firstData()
{
document.getElementById
("FD").innerHTML="Bhaskar";
return true ;
}
function secondData()
{
document.getElementById
("SD").innerHTML="Kumar";
return true ;
}
</script>
</head>
<body>
<h1> Welcome </h1>
<p id="FD"></p>
<p id="SD"></p>
<button onclick="JavaScript:firstData()">First
Data</button>
<button onclick="JavaScript:secondData()">First
Data</button>
</body>
</html>