473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

My non-working PHP radio button checker

w33nie
56
What I've been trying to do here is create a bit of php that will check one of 4 radio buttons if the value submitted in a text field on the previous page ($amount_front) is the same amount that the radio button is labelled as.

The value submitted on the previous page is a monetary amount, and the radio buttons are $10, $25, $50 and Other.

But if the user doesn't enter anything, I'd like it to select Other, but I'm not sure how I'd go about that either.


This code is before the <html> tag.
[php]
$amount_front = $_GET['amount_front'];

$ten = 'unchecked';
$twentyfive = 'unchecked';
$fifty = 'unchecked';
$other = 'unchecked';

if ($amount_front == '$10') {
$ten = 'checked';
}
else if ($amount_front == '10') {
$ten = 'checked';
}
else if ($amount_front == '$25') {
$twentyfive = 'checked';
}
else if ($amount_front == '25') {
$twentyfive = 'checked';
}
else if ($amount_front == '$50') {
$fifty = 'checked';
}
else if ($amount_front == '50') {
$fifty = 'checked';
}
[/php]

and this is the coding for each radio button (with their respective values)
[php]
<input name="amount" id="amount" type="radio" value="10" checked="<?php echo $ten; ?>" />
[/php]


(Yes I know I'm bad at php)
Sep 20 '07 #1
3 1925
you need to add in the following at the end of your last if statement.

[PHP]
else{
$other = checked;
}
[/PHP]
Sep 20 '07 #2
w33nie
56
Nope, didn't work.
:(
Sep 21 '07 #3
ak1dnar
1,584 Expert 1GB
Check this out:

  • $removed some unwanted if blocks
  • changed the the way of printing the checked/unchecked values within the second page radio button group.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $amount_front = $_GET['amount_front'];
  3.  
  4.     if ($amount_front == '10') {
  5.     $ten = 'checked="checked"';
  6.     }
  7.     elseif ($amount_front == '25') {
  8.     $twentyfive = 'checked="checked"';
  9.     }
  10.     elseif ($amount_front == '50') {
  11.     $fifty = 'checked="checked"';
  12.     }else{
  13.      $other = 'checked="checked"';
  14.     }
  15.     ?>
  16.  
  17. <html>
  18. <head>
  19.  
  20. </head>
  21.  
  22. <body>
  23. <p>
  24.   <label>
  25.   <input type="radio" name="RadioGroup1" value="10" <?php echo $ten; ?>/>
  26.     10</label>
  27.   <br />
  28.   <label>
  29.   <input type="radio" name="RadioGroup1" value="25"  <?php echo $twentyfive; ?>/>
  30.     25</label>
  31.   <br />
  32.     <label>
  33.   <input type="radio" name="RadioGroup1" value="other"  <?php echo $other; ?>/>
  34.     Other</label>
  35. </p>
  36. </body>
  37. </html>
  38.  
Sep 21 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
3
by: Mario | last post by:
Hello, I couldn't find a solution to the following problem (tried google and dejanews), maybe I'm using the wrong keywords? Is there a way to open a file (a linux fifo pipe actually) in...
25
by: Yves Glodt | last post by:
Hello, if I do this: for row in sqlsth: ________pkcolumns.append(row.strip()) ________etc without a prior:
32
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
14
by: Patrick Kowalzick | last post by:
Dear all, I have an existing piece of code with a struct with some PODs. struct A { int x; int y; };
11
by: ypjofficial | last post by:
Hello All, So far I have been reading that in case of a polymorphic class ( having at least one virtual function in it), the virtual function call get resolved at run time and during that the...
2
by: Ian825 | last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my...
399
by: =?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= | last post by:
PEP 1 specifies that PEP authors need to collect feedback from the community. As the author of PEP 3131, I'd like to encourage comments to the PEP included below, either here (comp.lang.python), or...
12
by: puzzlecracker | last post by:
is it even possible or/and there is a better alternative to accept input in a nonblocking manner?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.