php echo

Thread Solved

Join Date: Feb 2008
Posts: 49
Reputation: emhmk1 is an unknown quantity at this point 
Solved Threads: 0
emhmk1 emhmk1 is offline Offline
Light Poster

php echo

 
0
  #1
Sep 24th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: php echo

 
0
  #2
Sep 24th, 2008
Originally Posted by emhmk1 View Post
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 should work
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. </head>
  7.  
  8. <body>
  9. <?
  10. $checkboxes1 = array();
  11. $checkboxes1[] = "value1";
  12. $checkboxes1[] = "value2";
  13. ?>
  14. <form action="<? echo $_SERVER['REQUEST_URI']; ?>" method="post">
  15. <table cellpadding="0" cellspacing="0">
  16. <tr>
  17. <td>Selected options below</td>
  18. </tr>
  19. <?
  20. foreach($checkboxes1 as $value)
  21. {
  22. $checkedcode = "";
  23. $checkeddisplay = "";
  24. if(isset($_POST['chkCheck']) && is_array($_POST['chkCheck']) && in_array($value, $_POST['chkCheck']))
  25. {
  26. $checkedcode .= '<tr>
  27. <td>include code here if the checkbox was selected</td>
  28. </tr>';
  29. $checkeddisplay = 'checked="checked" ';
  30. }
  31. ?>
  32. <tr>
  33. <td><input type="checkbox" <? echo $checkeddisplay; ?>name="chkCheck[]" value="<? echo $value; ?>" /></td>
  34. </tr>
  35. <? echo $checkedcode; ?>
  36. <?
  37. }
  38. ?>
  39. </table>
  40. </form>
  41. </body>
  42. </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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 49
Reputation: emhmk1 is an unknown quantity at this point 
Solved Threads: 0
emhmk1 emhmk1 is offline Offline
Light Poster

Re: php echo

 
0
  #3
Sep 24th, 2008
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...
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: php echo

 
0
  #4
Sep 24th, 2008
Originally Posted by emhmk1 View Post
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...
This seems to work OK, just put your images in a folder under the document root called "rdo" and name your images to be the same as the value of the radio button, just replace the spaces with underscores.
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>Untitled Document</title>
  6. </head>
  7.  
  8. <body>
  9. <?
  10. $rdobuttons1 = array();
  11. $rdobuttons1[] = "value1";
  12. $rdobuttons1[] = "value2";
  13. ?>
  14. <form action="<? echo $_SERVER['REQUEST_URI']; ?>" method="post">
  15. <table cellpadding="0" cellspacing="0">
  16. <tr>
  17. <td>Selected option below</td>
  18. </tr>
  19. <?
  20. foreach($rdobuttons1 as $value)
  21. {
  22. $checkedcode = "";
  23. $checkeddisplay = "";
  24. if(isset($_POST['rdoButton']) && $_POST['rdoButton'] == $value)
  25. {
  26. $checkedcode .= '<tr>
  27. <td>&nbsp;<img border="0" src="images/rdo/' . str_replace(" ", "_", $value) . '.jpg" /></td>
  28. </tr>';
  29. $checkeddisplay = 'checked="checked" ';
  30. }
  31. ?>
  32. <tr>
  33. <td><input type="radio" id="<? echo str_replace(" ", "_", $value); ?>" <? echo $checkeddisplay; ?>name="rdoButton" value="<? echo $value; ?>" />&nbsp;<label for="<? echo str_replace(" ", "_", $value); ?>"><? echo ucwords($value); ?></label></td>
  34. </tr>
  35. <? echo $checkedcode; ?>
  36. <?
  37. }
  38. ?>
  39. <tr>
  40. <td><input type="submit" name="btnSubmit" value="Submit" /></td>
  41. </tr>
  42. </table>
  43. </form>
  44. </body>
  45. </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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 49
Reputation: emhmk1 is an unknown quantity at this point 
Solved Threads: 0
emhmk1 emhmk1 is offline Offline
Light Poster

Re: php echo

 
0
  #5
Sep 24th, 2008
Cheers dude, thats magic.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC