Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with checkbox and image javascript

Status
Not open for further replies.

zarosthegreat

Technical User
Nov 20, 2008
1
Hi people, I'm new to javascripting and i need some help!!
I'm trying to make a script which uses id's and name's to change values and image src's.

What I want, is to be able to select a checkbox, then click an image which then changes the 'src' of the image with the value of the checked checkbox.
AND if it's not too much to ask, i also need help with transferring the image src'es into a text box..
But It's more important that I get the "checkbox-to-image-src" part working.. so please help me with that first. :)!

I've accomplished similar scripts, but much, much simpler..




Here's the "vibe" and the basic idea of the code i want:

<!-- start code
<HTML>
<HEAD>
<TITLE>test</TITLE>
<script>
fuction CHK() {
var CHECKNAME = "checkbox.checked=true"; // Find checkbox which is checked - need serious help here..
var EXT = ".gif"; // Image file-type to be used in final replacement src
this.src="document.form1.'+ CHKNAME +'.value+EXT"; // Gets value from checkbox, and uses as img.src (replaces the image
}

function CONVERT() {
var sep = ","
CODEBOX.value="document.IMG0.src+sep+document.IMG1.src+sep+document.IMG2.src+sep+document.IMG3.src" // Basically gets all the image's src, seperated by commas, and get put into the CODEBOX textbox
}

</script>
</HEAD>
<BODY>
<form name=form1>
<img src=0.gif id=IMG0 onclick="CHECK()"><img src=0.gif id=IMG1 onclick="CHECK()"><img src=0.gif id=IMG2 onclick="CHECK()"><img src=0.gif id=IMG3 onclick="CHECK()"><br>
<input type=checkbox value=0 name=chk1>0<input type=checkbox value=1 name=chk2>1<input type=checkbox value=2 name=chk1>2<input type=checkbox value=3 name=chk1>3<br>
<input type="text" id=CODEBOX value=""><input type=submit value="get code" onclick="CONVERT()">
</form>
</BODY>
</HTML>
<!-- end code



If anyone can help me in anyway at all, even just a little, it would help me SO much.
i just to get started with it.


MUCH APPRECIATED!!!
 
There are a few issues with your code, but probably the big two:

1. You've opened an HTML comment right at the top, which you never close.

2. You are calling a function called CHECK which doesn't exist.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
You have also missed the 'n' from function in function CHK()

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Your code mixes and mismatches single and double quotes, changes the spelling of variable and function names, lots of problems.

Can you ask your teacher to help you get this sorted out?

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top