PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 19th, 2012, 01:08 PM
jpmul jpmul is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 27 jpmul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 38 m 44 sec
Reputation Power: 0
Checkbox Check Uncheck Problem

Hi
I have a bit of a dilemma.
I'm using onclick and onmouseup and onchange to submit values in a form. I usually let the user first choose all the values then i use a radio button to submit the changes, but i'm try to do it more on the fly so that every time they change a value the form submits and updates. Which i'm already doing. the but question is below the code

here is the php
PHP Code:
<?php
if (isset($_POST['ordernow'])) {
$sql="SELECT `quantity` from `mytable` where `filenr` = '$filenr'";
$result=mysql_query($sql$link);
$row mysql_fetch_assoc($result);
$quantity $row['quantity'];

if (empty(
$quantity)){
$quantity "250"
$exVat 262.28;
$Vat 262.28*0.14;
$Total 262.28*1.14// R299 total    
}
    
foreach(
$_POST['ordernow'] as $ordernow){ $filenr $ordernow ' ';}
$pieces explode("_"$filenr);
$filenr $pieces[0]; // piece1
$ordernow $pieces[1]; // piece2

$sql="UPDATE `mytable` set `ordernow` = '$ordernow' where `filenr` = '$filenr'";
//die ($sql);
mysql_query($sql$link);
header ('Location: page.php'); die ('3'); exit (0); 
}


if (isset(
$_POST['quantity'])) {
$quantity safe($_POST['quantity']);

$pieces explode("_"$quantity);
$filenr $pieces[0]; // piece1
$quantity $pieces[1]; // piece2

if ($quantity == "250"){ 
$exVat 262.28;
$Vat 262.28*0.14;
$Total 262.28*1.14// R299 total
}

if (
$quantity == "500"){ 
$exVat 350;
$Vat 350*0.14;
$Total 350*1.14//R399 total
}

if (
$quantity == "1000"){ 
$exVat 437.72;
$Vat 437.72*0.14;
$Total 437.72*1.14//R399 total
}

$sql="UPDATE `mytable` set `quantity` = '$quantity' ,`exVat` = '$exVat' ,`Vat` = '$Vat', `Total` = '$Total'  where `filenr` = '$filenr'";
//die ($sql);
mysql_query($sql$link);
header ('Location: page.php'); die ('3'); exit (0); 
}
?>


and the html with php to make the top php work
PHP Code:
<form action="" method="post" name="form">
     <
table width="105" border="0" cellspacing="0" cellpadding="0">
      <
tr align="center" class="history">
        <
th width="71">Quantity</th>
        <
th width="34">Select</th>
       </
tr>

<?
php 
$sql
="select * from `mytable` where `username` = '".$username."'";
$result=mysql_query($sql$link);
$row mysql_fetch_assoc($result)

$ordernow $row['ordernow'];
$quantity $row['quantity'];

?>
    <tr>
        <th>
        <select name="quantity" style="WIDTH: 60px" onchange="this.form.submit();">
          <option value="<?php echo $filenr."_250" ?><?php if ($quantity == "250"){ echo " selected='selected'";}else{}?>>250</option>
          <option value="<?php echo $filenr."_500" ?><?php if ($quantity == "500"){ echo " selected='selected'";}else{}?>>500</option>
          <option value="<?php echo $filenr."_1000" ?><?php if ($quantity == "1000"){ echo " selected='selected'";}else{}?>>1000</option>
        </select>
        </th>
        <th>
          <?php if ($ordernow == "1"){ echo "<input name=\"ordernow[]\" id=\"ordernow\" type=\"checkbox\" value=\"".$filenr."_0\" checked=\"checked\" onmouseup=\"this.form.submit();\" />";}else { echo "<input name=\"ordernow[]\" id=\"ordernow\" type=\"checkbox\" value=\"".$filenr."_1\" onchange=\"this.form.submit();\" />";} ?>
        </th>
       </tr>
   
    </table>
    </form > 

So what it does is when the user checks the record it gets checked.
And uncheck unchecks the record,
But the problem comes in when the quantity gets changed, Then it obviously posts the checkbox also and unchecks it and quantity stays unchange. (not good)
Only the second time round when the checkbox is empty it actualy changes the quantity.
This is undesired.
I would like to have each input method only be effected when that specific dropdown or checkbox was selected.
so that when quantity gets updated it does not affect the state of the checkbox.

Does anyone have a workaround for this please

Reply With Quote
  #2  
Old November 20th, 2012, 10:10 AM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 295 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 8 h 37 m 29 sec
Reputation Power: 5
I'm a bit lost with how you make it sound that every time the form is submitted, a checkbox alters to its opposite on its own. If I'm understanding the overall goal right, your intent is to do something similar to a shopping cart, where if you update quantity, it will update price to with your new values.

If you wish to do this in PHP the way it sounds, I would pretty much have 2 types of submits. I forgot how to do this, n am on my way out the work, so sorry for the lack of info, but 1 submit simply submits current info back to the page so it can update its items. Final submit is the forms true submit to toss the info into a database, or your intent.

Reply With Quote
  #3  
Old November 20th, 2012, 11:53 AM
jpmul jpmul is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 27 jpmul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 38 m 44 sec
Reputation Power: 0
My own shopping cart yes

I see yes
Like Submit the form but to Session variables.
I prefer the hard code way.
You see, the way the check box was updating and changing itself is cause its part of the form where the quantity is being updated.
I do it with onchange events for each drop down so every change the user makes gets inserted and updated into the database database.

I'm not getting the checkbox method right so ive changed the checkbox also into a dropdown.

The Session submit will be way to elaborate i think.
My code is working now but would like to figure the checkbox out.

Reply With Quote
  #4  
Old November 20th, 2012, 01:14 PM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 295 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 8 h 37 m 29 sec
Reputation Power: 5
Ah, I think I was a lil off on your issue. When you start, the checkbox may already be checked since it was defined as checked. You would like this to hold value and be able to change your quantity? If that is the case, I would just toss in a check to see if current quantity value in database matches that submitted by the form.

Reply With Quote
  #5  
Old November 20th, 2012, 01:21 PM
jpmul jpmul is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 27 jpmul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 38 m 44 sec
Reputation Power: 0
Yes I've tried that with the checkbox, didnt work.
It is exactly what i'm already doing with the dropdowns.

If posted value = db value then skip sql insert.

but the checkbox did not want to play ball so i tossed it for the dropdown which says yes or know.
But boy the checkbox looks so much better.

You can use my code to try it and see for yourself.
It's checked at first. then when i post the form it unchecked because of reversed checkbox values.
You see when its checked value is 0
When unchecked value is 1
This is because when you uncheck the box it has to post the opposite value all the time then you just go into the loop all the time

Reply With Quote
  #6  
Old November 20th, 2012, 01:54 PM
badger_fruit's Avatar
badger_fruit badger_fruit is offline
Confused badger
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2009
Location: West Yorkshire
Posts: 760 badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 5 h 15 m 18 sec
Reputation Power: 339
Quote:
Originally Posted by jpmul
Does anyone have a workaround for this please


Yes: Don't update like that; use a single submit button ("Update totals") and have it work out the changes then instead.

Besides, f the user selects the wrong value from the drop-down and then it updates the cart, they then have to re-select / submit the change. Not good or user-friendly.
__________________
The number for UK Emergencies is changing, the new number is 0118 999 881 999 119 7253

"For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
- George Orwell, 1984

Reply With Quote
  #7  
Old November 21st, 2012, 02:59 AM
jpmul jpmul is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 27 jpmul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 38 m 44 sec
Reputation Power: 0
The thing is i think the user experience will in this case will better rather than being diminished. Most people have broadband now a days.

There will mostly be more than one item and each item have about 6 option which can affect that items price outcome.

Good advice noted though

Reply With Quote
  #8  
Old November 21st, 2012, 07:49 AM
badger_fruit's Avatar
badger_fruit badger_fruit is offline
Confused badger
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2009
Location: West Yorkshire
Posts: 760 badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level)badger_fruit User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 5 h 15 m 18 sec
Reputation Power: 339
Quote:
Originally Posted by jpmul
The thing is i think the user experience will in this case will better rather than being diminished. Most people have broadband now a days.

There will mostly be more than one item and each item have about 6 option which can affect that items price outcome.

Good advice noted though


Well, although I have 60mb broadband it'd annoy the hell out of me if the whole page reloaded when I tried to make a change.

It'd have to be done via Ajax or a single 'update cart' option for me. Multiple selects and checkboxes are really quite easy, search this forum where I myself have made several posts about the subject - there'll be links to example pages which will help too.

Of course, it's up to you, you have my opinion.
Regards!

Reply With Quote
  #9  
Old November 21st, 2012, 08:35 AM
Triple_Nothing Triple_Nothing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 295 Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level)Triple_Nothing User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 3 Days 8 h 37 m 29 sec
Reputation Power: 5
Yep. That's the way I'd go. If you want instant updates after tiny changes, just write it to be done client-side, and don't bother truely submitting anything til it's in it's final state and truely ready to be submitted.

Reply With Quote
  #10  
Old November 21st, 2012, 04:07 PM
jpmul jpmul is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 27 jpmul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 38 m 44 sec
Reputation Power: 0
Cool Thanks

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Checkbox Check Uncheck Problem

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap