Attach a Script to a Button

Posted on 2007-07-29
Last Modified: 2010-04-16
I am able to design basic html websites, but I have no experience how to
attach a piece of script code to a button ...

I have to attach a button to each of the scripts a company provided for a demo ...

Can someone give me the basic syntax to attach the following code sample to run when the
user clicks a button?

<SCRIPT LANGUAGE="javascript1.2" type="text/javascript" SRC=""></SCRIPT>

Typically this type of script is just added to a html page and it automatically runs when the page
loads ... since I have 13 demos to show I want to just activate the code when the user selects the
one they want to view ...
Question by:AEII
    LVL 51

    Accepted Solution

    assuming your code to be run is encapsulated in the retrived file as
      function clickme() { ... }

    then  the button to execute it would be
     <button onClick="onclick();">click me</button>

    how about reading a book about HTML basics first?
    LVL 1

    Assisted Solution


    in your .js file you may have multiple functions defined, select the corrdt function and add it to your button like this:

    <input type="button" onclick="myclickfunc()">

    your .js file might look like this

    function myclickfunc()
       //code here
    alert("hello world!");

    Author Comment

    I appreciate your replies, but I did accomplish it another method ...
    I am disappointed in that a reply to have me read a HTML basic book first was
    given ... I prefer to see models and test and play around to better understand the code being performed ... not read someone's idea of how they want you to learn the subject they are considered an expert at ... I need much more kinestetic environments ...

    Also I thought this was why I pay for the subscription each year to be able to ask at times some very stupid questions ...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now