Web Analytics Made Easy -
StatCounter onClick Event Handler - CodingForum

Announcement

Collapse
No announcement yet.

onClick Event Handler

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • onClick Event Handler

    Hey all,

    I am very new to javascript and have a really quick, simple script I need help writing.

    I want to have a link on my page that when clicked, it will choose one of two radio buttons, and fill in a text field.

    So, here is what I want:

    Code:
    <input name="page_width" type="text"><br>
    <input name="page_width_type" type="radio" value="percent">&nbsp;&nbsp;
    <input name="page_width_type" type="radio" value="pixels"><br><br>
    <a href="#" onClick="WHAT GOES HERE">full screen</a>
    I want to add a link right below it that sets the textbox (page_width) to '100' and selects the first radio button (percent).

    Thanks,
    -influxer

  • #2
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    function Action(){
     document.fred.page_width.value='100';
     document.fred.page_width_type[0].checked=true;
    }
    //-->
    </script></head>
    
    <body>
    <form name="fred" >
    <input name="page_width" type="text"><br>
    <input name="page_width_type" type="radio" value="percent">&nbsp;&nbsp;
    <input name="page_width_type" type="radio" value="pixels"><br><br>
    <a href="#" onClick="Action();">full screen</a>
    </form>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/

    Comment


    • #3
      could I somehow fit the code from the Action() function into the onClick command?

      Comment


      • #4
        onclick="document.fred.page_width.value='100';document.fred.page_width_type[0].checked=true;"
        Vic

        God Loves You and will never love you less.

        http://www.vicsjavascripts.org/Home.htm

        If my post has been useful please donate to http://www.operationsmile.org.uk/

        Comment

        Working...
        X