Click on an Image, and set radio button value to true

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ameshkin

    Click on an Image, and set radio button value to true

    Hi guys,

    I'm a pretty good PHP programmer, but when it comes to JS, I just dont
    understand it! But I really need to learn. I'm having trouble doing
    the simplest thing!

    When someone clicks on this image, I want the radiobutton above it to
    be checked. Not that hard,but nothing I try seems to work. Can
    someone please help me?


    <form id="form1" method="post" action="">
    <input type="radio" name="radio" id="svc_tp_1" value="svc_tp_0 4" /></
    td>
    <img src="images/print.jpg" onClick="check( 'svc_tp_1')" />
  • dcx

    #2
    Re: Click on an Image, and set radio button value to true

    Do you really need javascript?

    Why not:

    <label><input type="radio"/><img/></label>

    Comment

    • Jim Carlock

      #3
      Re: Click on an Image, and set radio button value to true

      "dcx" <Youngblood.Car l@gmail.comwrot e:
      : <label><input type="radio"/><img/></label>

      Is that something new? It doesn't look like HTML nor XHTML. I'm
      curious. Did I miss out on something?

      --
      Jim Carlock
      Natural Cure For Pink-Eye (Conjunctivitis )





      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: Click on an Image, and set radio button value to true

        ameshkin wrote:
        I'm a pretty good PHP programmer, but when it comes to JS, I just dont
        understand it! But I really need to learn. I'm having trouble doing
        the simplest thing!
        Apparently.
        When someone clicks on this image, I want the radiobutton above it to
        be checked. Not that hard,but nothing I try seems to work. Can
        someone please help me?
        >
        <form id="form1" method="post" action="">
        <input type="radio" name="radio" id="svc_tp_1" value="svc_tp_0 4" /></
        td>
        <img src="images/print.jpg" onClick="check( 'svc_tp_1')" />
        Reduced to the necessary minimum (HTML 4.01 Transitional) and all invalid
        code dumped to /dev/null:

        <form action="" method="post">
        <input type="radio" name="radio" id="svc_tp_1" value="svc_tp_0 4"
        ><label for="svc_tp_1"> <img
        src="images/print.jpg" alt="Print"></label>
        <input type="submit">
        </form>

        Sorry, looks like there is no JS in there. But maybe someone else comes up
        with a fully-fledged scripted solution that introduces the accessibility issue.


        PointedEars
        --
        Use any version of Microsoft Frontpage to create your site.
        (This won't prevent people from viewing your source, but no one
        will want to steal it.)
        -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Click on an Image, and set radio button value to true

          Jim Carlock wrote:
          "dcx" <Youngblood.Car l@gmail.comwrot e:
          : <label><input type="radio"/><img/></label>
          >
          Is that something new?
          No, it turns 10 on December 24 next year.
          It doesn't look like HTML nor XHTML.
          *The above* is not. However, it can be written as Valid HTML 4.01 or
          XHTML 1.x. See my other reply.
          I'm curious. Did I miss out on something?
          Obviously.

          <http://www.w3.org/TR/REC-html40/>


          PointedEars
          --
          Anyone who slaps a 'this page is best viewed with Browser X' label on
          a Web page appears to be yearning for the bad old days, before the Web,
          when you had very little chance of reading a document written on another
          computer, another word processor, or another network. -- Tim Berners-Lee

          Comment

          • Suhas Dhoke

            #6
            Re: Click on an Image, and set radio button value to true

            On Jul 19, 4:37 am, ameshkin <amir.mesh...@g mail.comwrote:
            Hi guys,
            >
            I'm a pretty good PHP programmer, but when it comes to JS, I just dont
            understand it!  But I really need to learn.  I'm having trouble doing
            the simplest thing!
            >
            When someone clicks on this image, I want the radiobutton above it to
            be checked.  Not that hard,but nothing I try seems to work.  Can
            someone please help me?
            >
            <form id="form1" method="post" action="">
            <input type="radio" name="radio" id="svc_tp_1" value="svc_tp_0 4" /></
            td>
            <img src="images/print.jpg" onClick="check( 'svc_tp_1')" />

            If you really want to select the radio button, by using JavaScript,
            without using <labelelement ,
            then the following code will help you.


            <img src="images/print.jpg" alt="Print"
            onClick="docume nt.getElementBy Id('id_of_your_ radio_button'). checked =
            true;">

            Comment

            • Evertjan.

              #7
              Re: Click on an Image, and set radio button value to true

              Suhas Dhoke wrote on 19 jul 2008 in comp.lang.javas cript:
              If you really want to select the radio button, by using JavaScript,
              without using <labelelement ,
              then the following code will help you.
              >
              >
              <img src="images/print.jpg" alt="Print"
              onClick="docume nt.getElementBy Id('id_of_your_ radio_button'). checked
              true;">
              >
              ......).checked = true;">



              --
              Evertjan.
              The Netherlands.
              (Please change the x'es to dots in my emailaddress)

              Comment

              • SAM

                #8
                Re: Click on an Image, and set radio button value to true

                Jim Carlock a écrit :
                "dcx" <Youngblood.Car l@gmail.comwrot e:
                : <label><input type="radio"/><img/></label>
                >
                Is that something new? It doesn't look like HTML nor XHTML. I'm
                curious. Did I miss out on something?

                <labelin forms is pure html

                very useful for accessibility


                <p><label for="theId">Ple ase hit me to check the radio button choice
                1</label>
                <input type="radio" id="theId" name="choice" tabindex=10
                value="choice_1 "choice 1</p>

                So that could work with an image

                <p>
                <label for="theId">
                <img src="choice_1.g if" alt="button helper"
                tittle="hit me to check choice 1">
                </label>
                <input type="radio" id="theId" name="choice"
                tabindex=10 value="choice_1 ">
                choice 1
                </p>


                --
                sm

                Comment

                • ameshkin

                  #9
                  Re: Click on an Image, and set radio button value to true

                  On Jul 18, 4:37 pm, ameshkin <amir.mesh...@g mail.comwrote:
                  Hi guys,
                  >
                  I'm a pretty good PHP programmer, but when it comes to JS, I just dont
                  understand it!  But I really need to learn.  I'm having trouble doing
                  the simplest thing!
                  >
                  When someone clicks on this image, I want the radiobutton above it to
                  be checked.  Not that hard,but nothing I try seems to work.  Can
                  someone please help me?
                  >
                  <form id="form1" method="post" action="">
                  <input type="radio" name="radio" id="svc_tp_1" value="svc_tp_0 4" /></
                  td>
                  <img src="images/print.jpg" onClick="check( 'svc_tp_1')" />
                  onClick="docume nt.getElementBy Id('svc_tp_2'). checked =
                  true;"

                  Thanks guys,
                  The above is exactly what I was lookng for. i almost had it myself,
                  but because of a typo, it did not work correctly!

                  I really need to buy a js book. Javascript is not really powerful,
                  but there are many things you can do with it that are impossible with
                  other languages, which does make it very powerful in its own way.

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: Click on an Image, and set radio button value to true

                    ameshkin wrote:
                    [...]
                    onClick="docume nt.getElementBy Id('svc_tp_2'). checked = true;"
                    >
                    Thanks guys,
                    The above is exactly what I was lookng for.
                    It's not. To begin with, it uses host object's methods without
                    feature-testing for them first.
                    i almost had it myself, but because of a typo, it did not work correctly!
                    >
                    I really need to buy a js book.
                    Hardly. In fact, at this point my recommendation stands that no book about
                    JS is worth buying for a beginner. There is plenty of reference material
                    online, for free. While subscribing to this newsgroup and reading regularly
                    is generally a good idea when attempting to learn the language(s), you
                    should start with the newsgroup's FAQ <http://jibbering.com/faq/and go
                    from there.
                    Javascript is not really powerful, [...]
                    As a *beginner* talking about *"Javascript "* when there is no such language,
                    you are not exactly in a position to correctly assess the power of the
                    several different implementations of the ECMAScript Language Specification.

                    <http://PointedEars.de/es-matrix>


                    HTH

                    PointedEars
                    --
                    Use any version of Microsoft Frontpage to create your site.
                    (This won't prevent people from viewing your source, but no one
                    will want to steal it.)
                    -- from <http://www.vortex-webdesign.com/help/hidesource.htm>

                    Comment

                    Working...