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

Radio Button

Status
Not open for further replies.

woodlandstar

Technical User
Mar 7, 2008
5
US
All I am attempting to do is turn a slide show on or off. The link for this is


This works but the problem is that the selected button clears and I do not want it to clear. If it clears then the user does not know if the show is on or off. If I use just an alert to tell which button is checked then they do not clear, but if I put in the code to enable or disable the slide show then the buttons clear. How can I keep the buttons from clearing?

Thank You For Any Help

Code:

In the head I have
chosen = ""
len = document.f1.r1.length

for (i = 0; i <len; i++) {
if (document.f1.r1.checked) {
chosen = document.f1.r1.value
}

}

if (chosen == "Off") {
javascript:void(disableSlideMode());
}
else {
javascript:void(enableSlideMode(10));
}
}
</script>

In the body I have

<form NAME = f1>

<p align="center">
<input type = radio Name = r1 Value = "On" onClick =GetSelectedItem()>
On
<input type = radio Name = r1 Value = "Off" onClick =GetSelectedItem()>
Off
</p>

</form>
 
Try this:
Code:
<script type="text/javascript">
function GetSelectedItem(chosen)
{

if (chosen == "Off") {
disableSlideMode();
}
else {
enableSlideMode(10);
}
}
</script>


<p align="center"> 
<input type = radio Name = r1 Value = "On" onClick ="GetSelectedItem(this.value)">On 
<input type = radio Name = r1 Value = "Off" onClick ="GetSelectedItem(this.value)">Off</p>

I have NO idea why you used javascript:void in your original function.

Lee
 
Then you need to look at your other JS functions that are called. What I gave you will do what you asked, but you didn't show the other functions your JS refers to.

Lee
 
the two functions are fairly simple and there is nothing I can see that is clearing the buttons.

function enableSlideMode (newDelay) {
// Turns slide mode on
slideMode=Boolean(true);
if (newDelay > 0) {
slideDelay = newDelay;
}
showPhoto(glbCurrentPhoto); //necessary to reset URL parameters.
// glbSlideTimer=setTimeout('showNext();',(slideDelay*1000));
}

function disableSlideMode() {
slideMode = Boolean(false);
clearTimeout (glbSlideTimer);
showPhoto(glbCurrentPhoto); //necessary to reset URL parameters.
}
 
Gotta pull each function source out of you specifically?

What does showPhoto(glbCurrentPhoto) do?

This
Code:
slideMode = Boolean(false);
doesn't need Boolean. I've written a variety of Javascript slideshows from scratch, but none ever acted like this.

Lee
 
The show function is

function showPhoto(index) {
// Shows the photo with identified index
var theURL = "" + this.location;

// Strip parameters, if any present, from end of URL.
if (theURL.indexOf("?")>0) {
theURL = theURL.substring(0,theURL.indexOf("?"));
}

// Append the new photo index as a parameter.
theURL += "?photo=" + index;

// Append the slideshow mode as a parameter.
if (slideMode == true) {
theURL += "&slideMode=true";
theURL += "&slideDelay=" + slideDelay;
}

// Go to the constructed URL which has the new
// photo's index as a parameter.
this.location = theURL;
}
 
You're reloading the page with each image change, which resets the radio buttons to both blank.

Lee
 
Thanks for the answer...I guess there is simply no way to force a checked value since the page is being reloaded.

I got this code off the net...guess I need to find a different photo viewer. In the examples they simply used an On and Off link with enable and disable. I went to the radio buttons thinking that I could maintain the user choice. I did not understand that the entire page was being reloaded.

Thanks For Your Time
Bungo
 
Here's one I wrote that is pretty simple, and you should be able to modify it easily to meet your needs. It has the automatic slideshow included that you can change to work from the radio buttons.


Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top