| | |
php echo
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 49
Reputation:
Solved Threads: 0
Hi all,
This is going to seem a very basic sort of question so here goes....
i have a form with a couple of checkboxs and what i want to do is
echo the selected checkbox. for example;
if checkbox 1 is submitted then an image will be shown in a div underneath the form when it is submitted.
and if option 2 is selected then a differnt image will be shown and so on and so on.
all in the same page without redirecting and so on.
thanks in advance...
Cheers...
This is going to seem a very basic sort of question so here goes....
i have a form with a couple of checkboxs and what i want to do is
echo the selected checkbox. for example;
if checkbox 1 is submitted then an image will be shown in a div underneath the form when it is submitted.
and if option 2 is selected then a differnt image will be shown and so on and so on.
all in the same page without redirecting and so on.
thanks in advance...
Cheers...
•
•
•
•
Hi all,
This is going to seem a very basic sort of question so here goes....
i have a form with a couple of checkboxs and what i want to do is
echo the selected checkbox. for example;
if checkbox 1 is submitted then an image will be shown in a div underneath the form when it is submitted.
and if option 2 is selected then a differnt image will be shown and so on and so on.
all in the same page without redirecting and so on.
thanks in advance...
Cheers...
php 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 xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <? $checkboxes1 = array(); $checkboxes1[] = "value1"; $checkboxes1[] = "value2"; ?> <form action="<? echo $_SERVER['REQUEST_URI']; ?>" method="post"> <table cellpadding="0" cellspacing="0"> <tr> <td>Selected options below</td> </tr> <? foreach($checkboxes1 as $value) { $checkedcode = ""; $checkeddisplay = ""; if(isset($_POST['chkCheck']) && is_array($_POST['chkCheck']) && in_array($value, $_POST['chkCheck'])) { $checkedcode .= '<tr> <td>include code here if the checkbox was selected</td> </tr>'; $checkeddisplay = 'checked="checked" '; } ?> <tr> <td><input type="checkbox" <? echo $checkeddisplay; ?>name="chkCheck[]" value="<? echo $value; ?>" /></td> </tr> <? echo $checkedcode; ?> <? } ?> </table> </form> </body> </html>
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
•
•
Join Date: Feb 2008
Posts: 49
Reputation:
Solved Threads: 0
Thanks Robbob, thats pretty much on the money. however...
firstly im an idiot, i wanted radio buttons not checkboxes. we wont even go there!
Secondly, could we have it where each radio button has a different outcome? so if 1 is selected img 1 shows if the second button is selected then img 2 is shown...
Thanks again
Cheers...
firstly im an idiot, i wanted radio buttons not checkboxes. we wont even go there!
Secondly, could we have it where each radio button has a different outcome? so if 1 is selected img 1 shows if the second button is selected then img 2 is shown...
Thanks again
Cheers...
•
•
•
•
Thanks Robbob, thats pretty much on the money. however...
firstly im an idiot, i wanted radio buttons not checkboxes. we wont even go there!
Secondly, could we have it where each radio button has a different outcome? so if 1 is selected img 1 shows if the second button is selected then img 2 is shown...
Thanks again
Cheers...
php 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 xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <? $rdobuttons1 = array(); $rdobuttons1[] = "value1"; $rdobuttons1[] = "value2"; ?> <form action="<? echo $_SERVER['REQUEST_URI']; ?>" method="post"> <table cellpadding="0" cellspacing="0"> <tr> <td>Selected option below</td> </tr> <? foreach($rdobuttons1 as $value) { $checkedcode = ""; $checkeddisplay = ""; if(isset($_POST['rdoButton']) && $_POST['rdoButton'] == $value) { $checkedcode .= '<tr> <td> <img border="0" src="images/rdo/' . str_replace(" ", "_", $value) . '.jpg" /></td> </tr>'; $checkeddisplay = 'checked="checked" '; } ?> <tr> <td><input type="radio" id="<? echo str_replace(" ", "_", $value); ?>" <? echo $checkeddisplay; ?>name="rdoButton" value="<? echo $value; ?>" /> <label for="<? echo str_replace(" ", "_", $value); ?>"><? echo ucwords($value); ?></label></td> </tr> <? echo $checkedcode; ?> <? } ?> <tr> <td><input type="submit" name="btnSubmit" value="Submit" /></td> </tr> </table> </form> </body> </html>
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
![]() |
Similar Threads
- PHP Beginner Here (PHP)
- My embedded php code won't execute (PHP)
- Error when editing PHP lines in a theme file. (PHP)
- Urgent help with "echo" properties (PHP)
- I need some help with a php table (PHP)
- Php parser error when xml version is mentioned (PHP)
- updating 2 HTML tables on one PHP page (PHP)
- PHP Form Input (PHP)
Other Threads in the PHP Forum
- Previous Thread: Ur help please!!
- Next Thread: sos help
| Thread Tools | Search this Thread |
.htaccess ajax apache api array beginner binary broken buttons cakephp checkbox class cms code cron curl database date directory display download dynamic ebooks echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail mediawiki menu mlm mod_rewrite multiple mysql number oop paypal pdf php phpincludeissue phpmyadmin problem query radio random recursion regex remote script search server sessions sms soap source sp space speed sql subdomain syntax system table tag tutorial update upload url validation validator variable vbulletin video web websphere white xml youtube





