Click to See Complete Forum and Search --> : Defining my own object instead of using radiobuttons
Hello,
I have the following problem:
I want to do a web form where some information is collected. Now I want to have an object with the same functionality like a radiobutton (groupable and checked-state) but with different looks (want to use my own graphics).
I've been trying a lot of different things, but nothing will work for me.
Has anybody an idea how to do this? Or does anybody know of a script that could help me solve the problem?
Besides that: Does anyone know of a good JavaScript-Parser?
Greetings, mama.
PS: Excuse my bad English...
Khalid Ali
01-04-2004, 12:29 PM
Originally posted by mama
......Besides that: Does anyone know of a good JavaScript-Parser?
????
you should be able to do that using img elements onclick, onmousedown and onmouseup events
Certainly. That's what I'm trying to do...
But how?
Khalid Ali
01-04-2004, 01:16 PM
well first you will have to put the base image for regular radio button
<img src="base_radio.gif" onclick="ChangeImg(this);"/>
then when this button is clicked, in the ChagneImg function look for what image is being displayed
function ChangeImg(obj){
if(this.rc=="base_radio.gif"){
//change to clicked image
obj.src = "clickedImage.gif";
}else{
//change back to base image
obj.src = "clickedImage.gif";
}
}
Thats all there is...:D
Hey, sounds pretty easy...
I'll try right away...
Thanks a lot!!
That's not quite it.
That will just toggle the image, but what if I want to have a group of "radiobuttons", where only one of the buttons in the group can be checked?
Pittimann
01-04-2004, 03:40 PM
Hi!
How many buttons do you need??
Cheers - Pit
I need a different amount buttons in the groups. One radiobutton group consists of six buttons, another of four. Actually, it may vary when I get further with the questionary.
I played around a bit with the script Khalid Ali supplied. It won't even toggle, it will only change the image once. It seems as if the this.src="base_graphic.gif" statement is not working since only the ELSE part will be correctly executed.
Maybe I'm doing something wrong...
Khalid Ali
01-04-2004, 05:18 PM
Originally posted by mama
It won't even toggle, it will only change the image once.
lol..
I did not write the code thinking that you will copy and paste it and it will work.I was merely giving you a guide line.
The idea will work its only matter of coming up with your logic that what exactly is you wnat to achieve.
Here is another idea.
xip up some images and some descriptions you want for the radio buttons am sure some one will take a shot at it
Pittimann
01-05-2004, 04:02 AM
Hi!
I put the stuff in a .zip because it is nicer playing with it having images. Just unzip the two images and the .htm into one directory and check it out...
Cheers - Pit
Hello Pittiman,
perfect!!! I am really happy to have your solution. It's just what I need. Actually I was close to a similar solution, but for some reason I made a syntax error I couldn't figure out.
By the way: Would you know how to use the GetElementsByName-function. I suppose it will give you an array of elements, but how can one use this array?
Thanks again,
mama
Pittimann
01-06-2004, 05:44 AM
Hi!
Afaik, you have to specify the element's (or elements' - if more than one with the same name exist) name when you use getElementsByName. That would mean, you cannot get an array of all elements in a document which have a name without knowing AND specifying them.
Do you need that for form elements?? If so, please post again...
Cheers - Pit