phpgoal Posted June 12, 2013 Share Posted June 12, 2013 Hello, I am calling JS funciton from HTML head. I want to see 'Click' button only if the date is equal to 'June 2013'. If the date is not equal to 'June 2013', I dont want to see 'Click' button. Not working. Please help! <html> <head> <script type="text/javascript"> var datestr =............. if (datestr == 'June 2013'){<button onclick="myFunction1('MS','QA')">Click</button> </script> </head> <body> <SCRIPT LANGUAGE="JavaScript">function myFunction1(name,job){alert("Welcome " + name + ", the " + job);} </script> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/279078-calling-javascript-function-from-html-head/ Share on other sites More sharing options...
codefossa Posted June 12, 2013 Share Posted June 12, 2013 <html> <head> <title>Xaotique - JS Page</title> <script type="text/javascript"> // Wait for the page to load before executing JS. window.addEventListener("load", function() { // Set the datestring for comparison. var datestr = window.document.querySelector("#datestr").innerHTML; // Compare it .. if (datestr == "June 2013") { // Create the button and set attributes. var myButton = window.document.createElement("button"); myButton.innerHTML = "Click Me!"; myButton.id = "myButton"; // Append the button to the body. window.document.body.appendChild(myButton); // Wait for the button to be clicked. myButton.addEventListener("click", function() { var name = "MS", job = "QA"; alert("Welcome " + name + ", the " + job + "!"); }); } }, false); </script> </head> <body> <p id="datestr">June 2013</p> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/279078-calling-javascript-function-from-html-head/#findComment-1435602 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.