I’m not good at all with functions, and learning JavaScript, I need a little help on one of the examples I’m making to learn it. I have a question. How do I make it so that the next button is shown only when the one before it is clicked? (For example, you can’t see the Yahoo button without clicking Google first) Here’s the code:
<html>
<head>
<script type="text/javascript">
function show_prompt()
{
var name=prompt("Your Name");
if (name!=null && name!="")
{
alert("Thanks for clicking! You will now be redirected to Google.com");
window.open("http://www.google.com/"};
}
</script>
<script type="text/javascript">
function show_alert()
{
alert("Thanks for clicking me! You are now going to Yahoo.com!");
window.open("http://www.yahoo.com");
}
</script>
<script type="text/javascript">
function show_alert1()
{
alert("Thanks for clicking. Have fun on facebook!");
window.open("http://www.facebook.com/");
}
</script>
</head>
<body>
<ul>
<li><input type="button" onclick="show_prompt()" value="Google" />
<li><input type="button" onclick="show_alert()" value="Yahoo" />
<li><input type="button" onclick="show_alert1()" value="Facebook" />
</ul>
</body>
</html>
Give the buttons id’s and then set their css display property as none to make them invisible (and not take up any space).
The function showNext then shows the button of the ID that is passed into the function. See above when the function is called I pass in either ‘btnYahoo’ or ‘btnFacebook’, depending on which one I want to show next.
Hope that helps