Reply
Math sum help
Old 01-17-2006, 10:07 PM Math sum help
Average Talker

Posts: 23
I have a form where zip codes can be looked up that return the zip and the quantity of address within that zip. What I would like is when they check the checkboxes for a zip it sums up the total as they click more and more. Can this be done, below is my code:
PHP Code:
<h2>Zip code lookup</h2>
<
p>This form will help you search for available zip codes and calculate the number of recipients in those zip codes.</p>
<
form action="test.php" method="post">
<
input name="Do" type="hidden" value="Lookup">
<
p>Please enter a zip code (0-5 digits):&nbsp;&nbsp;<input type="text" name="zip_code" size="6">&nbsp;<input type="submit" value="Lookup" class="submit"></p>
<
table cellpadding="3" cellspacing="4" border="0" width="425" class="CategoryTable">
<
tr>
    <
td style="color:#FFFFFF; background-color:#000000;">Select a Zip</td>
    <
td style="color:#FFFFFF; background-color:#000000;">Add/Remove</td>
    <
td style="color:#FFFFFF; background-color:#000000;">Your Zip Code List</td>
</
tr>
<
tr>
    <
td>
        <
table cellpadding="2" cellspacing="2" border="0" width="100%" class="CategoryTable">
        <
tr>
            <
td><strong>Choose</strong></td>
            <
td align="center"><strong>Zip</strong></td>
            <
td><strong>Quantity</strong></td>
        </
tr>
        <
tr bgcolor=#EEEEEE>
            
<td><input type="checkbox" name="zip_id[]" value="5828"></td>
            <
td>22301</td>
            <
td align="right">3855<input type="hidden" name="h22301" value="3855"></td>
        </
tr>
        <
tr bgcolor=#FFFFFF>
            
<td><input type="checkbox" name="zip_id[]" value="5829"></td>
            <
td>22302</td>
            <
td align="right">4403<input type="hidden" name="h22302" value="4403"></td>
        </
tr>
        <
tr bgcolor=#EEEEEE>
            
<td><input type="checkbox" name="zip_id[]" value="5830"></td>
            <
td>22303</td>
            <
td align="right">2722<input type="hidden" name="h22303" value="2722"></td>
        </
tr>
        <
tr bgcolor=#FFFFFF>
            
<td><input type="checkbox" name="zip_id[]" value="5831"></td>
            <
td>22304</td>
            <
td align="right">5797<input type="hidden" name="h22304" value="5797"></td>
        </
tr>
        <
tr bgcolor=#EEEEEE>
            
<td><input type="checkbox" name="zip_id[]" value="5832"></td>
            <
td>22305</td>
            <
td align="right">2877<input type="hidden" name="h22305" value="2877"></td>
        </
tr>
        <
tr bgcolor=#FFFFFF>
            
<td><input type="checkbox" name="zip_id[]" value="5833"></td>
            <
td>22306</td>
            <
td align="right">6156<input type="hidden" name="h22306" value="6156"></td>
        </
tr>
        <
tr bgcolor=#EEEEEE>
            
<td><input type="checkbox" name="zip_id[]" value="5834"></td>
            <
td>22307</td>
            <
td align="right">3039<input type="hidden" name="h22307" value="3039"></td>
        </
tr>
        <
tr bgcolor=#FFFFFF>
            
<td><input type="checkbox" name="zip_id[]" value="5835"></td>
            <
td>22308</td>
            <
td align="right">4750<input type="hidden" name="h22308" value="4750"></td>
        </
tr>
        <
tr bgcolor=#EEEEEE>
            
<td><input type="checkbox" name="zip_id[]" value="5836"></td>
            <
td>22309</td>
            <
td align="right">8456<input type="hidden" name="h22309" value="8456"></td>
        </
tr>
        <
tr bgcolor=#FFFFFF>
            
<td><input type="checkbox" name="zip_id[]" value="5837"></td>
            <
td>22310</td>
            <
td align="right">8594<input type="hidden" name="h22310" value="8594"></td>
        </
tr>
        <
tr bgcolor=#EEEEEE>
            
<td><input type="checkbox" name="zip_id[]" value="5838"></td>
            <
td>22311</td>
            <
td align="right">1846<input type="hidden" name="h22311" value="1846"></td>
        </
tr>
        <
tr bgcolor=#FFFFFF>
            
<td><input type="checkbox" name="zip_id[]" value="5839"></td>
            <
td>22312</td>
            <
td align="right">5642<input type="hidden" name="h22312" value="5642"></td>
        </
tr>
        <
tr bgcolor=#EEEEEE>
            
<td><input type="checkbox" name="zip_id[]" value="5840"></td>
            <
td>22314</td>
            <
td align="right">7283<input type="hidden" name="h22314" value="7283"></td>
        </
tr>
        <
tr bgcolor=#FFFFFF>
            
<td><input type="checkbox" name="zip_id[]" value="5841"></td>
            <
td>22315</td>
            <
td align="right">8592<input type="hidden" name="h22315" value="8592"></td>
        </
tr>

        </
table>
    </
td>
    <
td valign="top" align="center"><input type="submit" name="Do" value=" >> "><br><br><input type="submit" name="Do" value=" << "></td>
    <
td valign="top">
        <
table cellpadding="2" cellspacing="2" border="0" width="100%" class="CategoryTable">
        <
tr>
            <
td><strong>Remove</strong></td>
            <
td><strong>Zip</strong></td>
            <
td><strong>Quantity</strong></td>
        </
tr>
        </
table>
    </
td>
</
tr>
</
table>
</
form
tobeyt23 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 01-18-2006, 09:15 AM
funkdaddu's Avatar
Web Design Snob

Posts: 636
Yes, it's possible, but is there a reason for the hidden field? Can't you just have the checkbox be like:

<input type="checkbox" name="22301" value="3855">

Also, technically, you can't have 2 objects with the same name (zip_id[]) and I don't think that the brackets [] are valid name characters as they are used to represent an array in JS.

For the script, just have when a check box is clicked, it clears zip code list, (to start from scratch) loops through all the checkboxes and if it's selected, it adds it to the box. I can help if you can explain how the hidden field works...
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 01-18-2006, 09:32 AM
Average Talker

Posts: 23
Thanks, the hidden stuff actually came from another js i was trying i meant to remove it as it does nothing currently. As for the [] I was using that to loop thur for a php script when adding to the database when the user submits the zips they want. Hope this clears up a bit.
tobeyt23 is offline
Reply With Quote
View Public Profile
 
Old 01-18-2006, 10:02 AM
funkdaddu's Avatar
Web Design Snob

Posts: 636
Well the bracket may be somewhat of a problem, being an invalid character for a name, and having them all named the same thing means you can't call them individually. I.E. if I try to call the first one, not only is it named the same as all the other checkboxes, but since it has the brackets, when you do call it by name (document.form[0].zip_id[].value) it thinks that zip_id is referencing an array without a selected ordinal.

We'll see if we can work around that. What does the value of the input button mean? The value of the checkbox for the 22301 Zip code is 5828 - what does that number represent? Isn't the real value 3855? that's the number of recipients right?

Last edited by funkdaddu : 01-18-2006 at 10:07 AM.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 01-18-2006, 10:15 AM
Average Talker

Posts: 23
The 5828 is the zip_id for that zip in my database, that is what i am looking for when they submit the form to place in the database. Any suggestions to work this will be accepted
tobeyt23 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Math sum help
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.15846 seconds with 12 queries