All i need is a script to check a set of radio buttons and show content depending on what one is currently selected.
Sounds Easy and i hope some one has or could make a script.
![]()
![]()
Thanks Alot
All i need is a script to check a set of radio buttons and show content depending on what one is currently selected.
Sounds Easy and i hope some one has or could make a script.
![]()
![]()
Thanks Alot
Could you be a little more specific? Do you want the radio buttons and the content that changes to be on the same page? Or do you want the radio buttons in a form, where the content is displayed after the form is submitted? Also, does your server support php?
Woops my bad,
i want it to be able to show it on the same page without submitting the form.
And yes my server support php.
Thanks
Here's one way of doing it.
Code:<html> <head> <title>radio button example</title> </head> <body> <?php $numChoices = 6; $choices = array(6); $choices[0] = "choice 0"; $choices[1] = "choice 1"; $choices[2] = "choice 2"; $choices[3] = "choice 3"; $choices[4] = "choice 4"; $choices[5] = "choice 5"; echo '<form name="form1" action="' . $_SERVER['PHP_SELF'] . '" method="post">'; $op = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : "0"; for ($i=0; $i<$numChoices; $i++) { echo '<input type="radio" name="choice" value="' . $i . '"'; if ((int)$op == $i) echo ' checked'; echo ' onchange="document.form1.submit()"> '; echo $choices[$i] . "<br>\r\n"; } echo '</form>'; switch ($op) { case "0": echo 'You chose 0'; break; case "1": echo 'You chose 1'; break; case "2": echo 'You chose 2'; break; case "3": echo 'You chose 3'; break; case "4": echo 'You chose 4'; break; case "5": echo 'You chose 5'; break; } ?> </body> </html>
Last edited by Blake; 02-28-2007 at 09:45 PM.
There is also the Chained Selection
It's not radio buttons, but can be adapted to do so.
(nice looking script Blake, you just whip that up?)
{CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
Follow Me on Twitter: @InkingHubris
PHP Code:$result = mysql_query("SELECT finger FROM hand WHERE id=3");
echo $result;
It isn't really dynamic... just automatically submitting the form.
He said without submitting.
However, the need depends on other variables, since now this might work in that the user does not need to click submit, if that's all that was desired.
To load this into an existing page as part of the page, it would be more difficult.
Seems like this might be more suited for ajax. Though, if possible to avoid ajax, it makes sense. I'm still not quite sure what is needed.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
If it's really important that the content be truly dynamic, I would put the content to change in an iframe, and just change the source to point to one of several files when a button is clicked. Trying to change the html of the whole page would be a nightmare, I think.
I could come up with a script that does that, Reion, if that's what you want.
Ajax changing the contents of a div is a very standard practice.
I don't really know how to do it, but I've seen it plenty.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
My script here can do it, although it would be better off not using <label> -- I should probably modify it at some point. Blake's idea is the best, though.Don't access it as document.form1, access it as document.forms['form1']. The former is rather non-standard.Code:echo ' onchange="document.form1.submit()"> ';If you're going to type-cast manually, you might as well take advantage of it by using ===Code:if ((int)$op == $i)![]()
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Bookmarks