|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Hello to all of you,
Somebody please help. I am quite a newbie in php. 1. How do i write the values of my checkbox as array? The value "Home" is equivalent to $30.00. The same goes with "About Us" and "Services/Products" Here's the piece of my html form: <form name="form1" method="post" action="quote.php"> <input type="checkbox" name="chkProvide[]" value="Home> Home<br> // Home has a corresponding value of $30.00 <input type="checkbox" name="chkProvide[]" value="About Us"> About Us<br> //About Us also has a corresponding value of $ 30.00 <input type="checkbox" name="chkProvide[]" value="Services/Products"> Services / Products<br> //Services/Products also has a corresponding value of $ 30.00 2. How do i display the checked items in another form using Post method with their corresponding price and their total? I've tried using foreach() but can't get it to work. Help is very much appreciated Thanks in advance! |
|
#2
|
|||
|
|||
|
Since I know how disappointing it is when nobody answers you post, I'll try and start you off ....
... try indexing the array ... <input type="checkbox" name="chkProvide[0]" value="Home> Home<br> // Home has a corresponding value of $30.00 <input type="checkbox" name="chkProvide[1]" value="About Us"> About Us<br> //About Us also has a corresponding value of $ 30.00 <input type="checkbox" name="chkProvide[2]" value="Services/Products"> Services / Products<br> //Services/Products also has a corresponding value of $ 30.00 Once the array in indexed, you should be able to loop through it. |
|
#3
|
|||
|
|||
|
Thanks.
But how am i going to write the values for my Home, About Us, and Products/Services in my html form, which is $30.00? Isn't it that we can loop through it by just using foreach()? |
|
#4
|
|||
|
|||
|
To be honest, I'm not exactly clear on what you're trying to do. However ...
If you want to pass the value (30), you can do it this way: <input type="checkbox" name="chkProvide[Home]" value="30"> <input type="checkbox" name="chkProvide[About]" value="30"> <input type="checkbox" name="chkProvide[Services]" value="30"> If a box is checked, 30 will be passed as the value for the Index. If the box is not checked, no index or value will be passed. If no index or value is passed, you could use an if statement to assign a value of zero, it that's what you want to do. if($chkProvide[Home] != 30){ $chkProvide[Home] = 0; } if($chkProvide[About] != 30){ $chkProvide[About] = 0; } if($chkProvide[Services] != 30){ $chkProvide[Services] = 0; } Then, in the form ... echo("<input type='hidden' name='Home' value='$chkProvide[Home]'>"); etc ... I have to sign off now. I hope this is of some help. Good luck. |
|
#5
|
|||
|
|||
|
Thanks bhoy!
I was able to make it work! I'll post my code as soon as i finished it. You're a great help. Thanks!![]() |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > checkbox array problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|