By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,712 Members | 2,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,712 IT Pros & Developers. It's quick & easy.

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

P: n/a
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')" />
Jul 18 '08 #1
Share this Question
Share on Google+
9 Replies


P: n/a
dcx
Do you really need javascript?

Why not:

<label><input type="radio"/><img/></label>
Jul 19 '08 #2

P: n/a
"dcx" <Yo*************@gmail.comwrote:
: <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)
http://www.associatedcontent.com/art...nctivitis.html


Jul 19 '08 #3

P: n/a
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_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:

<form action="" method="post">
<input type="radio" name="radio" id="svc_tp_1" value="svc_tp_04"
><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>
Jul 19 '08 #4

P: n/a
Jim Carlock wrote:
"dcx" <Yo*************@gmail.comwrote:
: <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
Jul 19 '08 #5

P: n/a
On Jul 19, 4:37*am, ameshkin <amir.mesh...@gmail.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_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 <labelelement,
then the following code will help you.
<img src="images/print.jpg" alt="Print"
onClick="document.getElementById('id_of_your_radio _button').checked =
true;">
Jul 19 '08 #6

P: n/a
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 <labelelement,
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;">

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 19 '08 #7

P: n/a
SAM
Jim Carlock a écrit :
"dcx" <Yo*************@gmail.comwrote:
: <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">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>
--
sm
Jul 19 '08 #8

P: n/a
On Jul 18, 4:37*pm, ameshkin <amir.mesh...@gmail.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_04" /></
td>
<img src="images/print.jpg" onClick="check('svc_tp_1')" />
onClick="document.getElementById('svc_tp_2').check ed =
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.
Jul 21 '08 #9

P: n/a
ameshkin wrote:
[...]
onClick="document.getElementById('svc_tp_2').check ed = 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>
Jul 22 '08 #10

This discussion thread is closed

Replies have been disabled for this discussion.