| | |
Newbie needs HELP with Radio Buttons.
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jun 2009
Posts: 3
Reputation:
Solved Threads: 0
Hi
I have an HTML document with a table that is 3 rows of 3 cells each, that presents 9 flash presentations in those cells.
I want to use a pair of radio buttons to toggle the presentations in those cells as follows.
The page will load with a "jpg" or "gif" image replicated in each table cell and the "Display OFF" radio button selected.
Toggling the "Display ON" radio button will activate the section of page "code" that activates all of the 9 flash presentations in place of the replications of the "jpg" or "gif" image in each of the table cells.
I use CSS and JavaScript but only informally so and much of what I have learned is self-taught or from experimentation. HELP! I want to stick with my table and avoid Form tags.
"Simple is Best" is probably the most useful approach. Thanks :-)
I have an HTML document with a table that is 3 rows of 3 cells each, that presents 9 flash presentations in those cells.
I want to use a pair of radio buttons to toggle the presentations in those cells as follows.
The page will load with a "jpg" or "gif" image replicated in each table cell and the "Display OFF" radio button selected.
Toggling the "Display ON" radio button will activate the section of page "code" that activates all of the 9 flash presentations in place of the replications of the "jpg" or "gif" image in each of the table cells.
I use CSS and JavaScript but only informally so and much of what I have learned is self-taught or from experimentation. HELP! I want to stick with my table and avoid Form tags.
"Simple is Best" is probably the most useful approach. Thanks :-)
•
•
Join Date: Aug 2007
Posts: 165
Reputation:
Solved Threads: 18
Here's a 'simple' method that is 'close' to what you stated. It's very high level, lacking most detail, but will do what you said you wanted once implemented correctly. I taught myself all this by trying all manner of stuff and reading the Oreilly JS book; it's easier to learn if you have some clue where to start. 
Prepare a <script> element that defines displayPresentation = 1; (see below), an associative array of the images to display, and an associative array of the SWF to display, and three functions.
Then write two functions: activateImage() and activateFlash(). The activateImage() function replaces the innerHTML content for each cell (getElementById("RC-*")) with <img...> elements. The activateFlash() function replaces the innerHTML for each cell with code to display the flash presentations.
Next write a third function: togglePresentation() which checks if (displayPresentation == 0) activateFlash() else activateImage(), and then sets displayPresentation = !displayPresentation. Finally return false to prevent the button from doing its default action. This function can optionally change the button's text or image to indicate which action it will take.
That's it for the <script> element; it should reside in the web page just before your table definition.
Now create your table cells with row-col ids, like: , so they display the default images. If you're on top of things, you'll define your image and swf arrays using indices that happen to be identical to your chosen IDs and happen to match the row and column numbers so you can use nested for loops to cycle through them.

Finally, you create a <button ...> element with no action but with an ONCLICK attribute. The ONCLICK script simply calls togglePresentation().
This will keep you busy for a week or three, since you have to learn ECMAScript (JavaScript), which isn't *too* hard to learn, and then learn to clearly separate that language from HTML and from PHP (or whatever server-side language you use), and clearly separate the three both in the code and in your head, which are much harder. They are three completely separate things running in completely separate environments. Here's a hint: be very careful to keep track of single- and double-quotes in your HTML, in your script code, and in the HTML you script code is generating; you will trip on this many times, and escaping them as needed can be a challenge.
Oh, you said you want to use radio buttons. These can work, too. I'll leave it as an exercise for you to figure out how to change the togglePresentation() function to switchPresentation().
Oh, yeah. Written right, the page won't reload every time the display is toggled.

Prepare a <script> element that defines displayPresentation = 1; (see below), an associative array of the images to display, and an associative array of the SWF to display, and three functions.
Then write two functions: activateImage() and activateFlash(). The activateImage() function replaces the innerHTML content for each cell (getElementById("RC-*")) with <img...> elements. The activateFlash() function replaces the innerHTML for each cell with code to display the flash presentations.
Next write a third function: togglePresentation() which checks if (displayPresentation == 0) activateFlash() else activateImage(), and then sets displayPresentation = !displayPresentation. Finally return false to prevent the button from doing its default action. This function can optionally change the button's text or image to indicate which action it will take.
That's it for the <script> element; it should reside in the web page just before your table definition.
Now create your table cells with row-col ids, like:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<td id="RC-11"><img ...></td>

Finally, you create a <button ...> element with no action but with an ONCLICK attribute. The ONCLICK script simply calls togglePresentation().
This will keep you busy for a week or three, since you have to learn ECMAScript (JavaScript), which isn't *too* hard to learn, and then learn to clearly separate that language from HTML and from PHP (or whatever server-side language you use), and clearly separate the three both in the code and in your head, which are much harder. They are three completely separate things running in completely separate environments. Here's a hint: be very careful to keep track of single- and double-quotes in your HTML, in your script code, and in the HTML you script code is generating; you will trip on this many times, and escaping them as needed can be a challenge.
Oh, you said you want to use radio buttons. These can work, too. I'll leave it as an exercise for you to figure out how to change the togglePresentation() function to switchPresentation().

Oh, yeah. Written right, the page won't reload every time the display is toggled.
Last edited by Fest3er; Jun 8th, 2009 at 11:59 pm.
Cap'n Sir,
Something like this maybe:
Airshow
Something like this maybe:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title>Airshow :: Untitled</title> <style> #myVideos { } #myVideos td { width:100px; height:100px; background-color:#818bf5; } </style> <style title="on_styles"> #myVideos td { background-color:#c743fb; } </style> <script> function sw(state){ var rule_sheet = getStyleSheet('on_styles'); if(state) { rule_sheet.disabled = false;//replace this with code to switch videos on } else { rule_sheet.disabled = true;//replace this with code to switch videos off } } //This function is not germain to the problem. It just gives a visual effect. function getStyleSheet(title) { for(var i=0; i<document.styleSheets.length; i++) { var sheet = document.styleSheets[i]; if(sheet.title == title) { return sheet; } } } onload = function(){ sw(0);//This ensures everything is initialised to the off state. } </script> </head> <body> <table id="myVideos" callpadding="6" border> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td></tr> </table> <input id="R_off" type="radio" name="switch" value="off" onclick="sw(0);" checked><label for="R_off">Off</label> <input id="R_on" type="radio" name="switch" value="on" onclick="sw(1);"><label for="R_on">On</label> </body> </html>
Airshow
![]() |
Similar Threads
- Adding Radio Buttons to Data from DB (Visual Basic 4 / 5 / 6)
- javascript radio buttons and insanity (JavaScript / DHTML / AJAX)
- dynamically generated textboxes & radio buttons php, insert into db (PHP)
- binding radio buttons (VB.NET)
- javascript: radio buttons (JavaScript / DHTML / AJAX)
- IE6 - dialogue boxes , check boxes and radio buttons work very slowly after hijacking (Viruses, Spyware and other Nasties)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Javascript- Hoe to delete rows by id.
- Next Thread: Help with pop-up window position
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child class close column createrange() css cursor date debugger dependent disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl math media microsoft mimic object onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post problem programming progressbar regex runtime scroll search security select shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n





