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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio button - OnClick

Status
Not open for further replies.

eyal

Programmer
May 15, 2000
38
IL
Hi,
I have 10 radio buttons on a form, on click of one of them I want the page to refresh itself and enter a value (of the chosen radio button) to a database, how do I know which button had been chosen and how do I refresh the page on that event
Thanks
Eyal
 
Consider the following

<form name=frm1 action=trim.asp>
<input name=radio1 type=radio value=1 onclick=&quot;radio_click(this);&quot;>
<input name=radio1 type=radio value=2 onclick=&quot;radio_click(this);&quot;>
<input name=radio1 type=radio value=3 onclick=&quot;radio_click(this);&quot;>
</form>

you can have a Java script...
function radio_click(radio1)
{
//radio1.value will give u the value of the button clicked
//the page can be refreshed using document.frm1.submit();
}

regards,
Mike
 
Thanks,
On this page I got a picture that is taken from a database, I'm showing the picture using &quot;img src=rs.imageUrl&quot;, on each click on the radio buttons I want the recordset to move to the next record, where should I write the &quot;rs.movenext&quot; ?
Thanks again
Eyal
 
rs.movenext happens at the server side and so may not be suitable for u...

Since you are having only 10 images, you can load the image urls into an array on the body onload() function

Then on the click event of the radio button, you can assign the urls appropiately.

for e.g
function radio_click(radio1)
{
document.frm1.img.src=imgArr[radio1.value];
}

where img is the name of the image tag
and imgArr is where the image urls are loaded..

hope this helps,
Mike


 
I have more than 10 images, in the future I'll have hundrads, I want on every click on any of the radio buttons to switch image, is it possible?
Thanks
Eyal
 
You can still do it...
To be efficient, you will have to load the image urls into the array taking care that the radio button's value and the array index match..

For a radio button value of '1', the image URL should be in imgArr[1] and so on. The code above will work for any no: of images... jus' that it will take more time for the page to load, since the array has to be populated with the image Urls... Try it out and see if the time-factor suits your requirements...

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top