Jump to content

Calling Javascript function from html head


phpgoal

Recommended Posts

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>
Link to comment
Share on other sites

 

<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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.