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

A

ameshkin

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_04" /></
td>
<img src="images/print.jpg" onClick="check('svc_tp_1')" />
 
T

Thomas 'PointedEars' Lahn

ameshkin said:
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_04" /></
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:

<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
 
S

Suhas Dhoke

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_04" /></
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 <label> element,
then the following code will help you.


<img src="images/print.jpg" alt="Print"
onClick="document.getElementById('id_of_your_radio_button').checked =
true;">
 
E

Evertjan.

Suhas Dhoke wrote on 19 jul 2008 in comp.lang.javascript:
If you really want to select the radio button, by using JavaScript,
without using <label> element,
then the following code will help you.


<img src="images/print.jpg" alt="Print"
onClick="document.getElementById('id_of_your_radio_button').checked
true;">

......).checked = true;">
 
S

SAM

Jim Carlock a écrit :
: <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?


<label> in forms is pure html

very useful for accessibility


<p><label for="theId">Please 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.gif" 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>
 
A

ameshkin

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_04" /></
td>
<img src="images/print.jpg" onClick="check('svc_tp_1')" />

onClick="document.getElementById('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.
 
T

Thomas 'PointedEars' Lahn

ameshkin said:
[...]
onClick="document.getElementById('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
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top