slaterino Posted January 5, 2010 Share Posted January 5, 2010 I have a form that I want to load automatically when the page loads. The basic code for this form is: <form action="basket.php?action=update" method="post" id="cart"> <input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /> <button type="submit">Update cart</button> </form> Is there a way I could use PHP to make this form load automatically when the page loads?? I just really want the $qty value to be updated and this seems like the best way of doing this! Russ Quote Link to comment Share on other sites More sharing options...
ChaosKnight Posted January 5, 2010 Share Posted January 5, 2010 I don't understand what your trying to do, what do you mean with "automatically"? Is it something that should load without a browser refresh? Because then you can load the form in a div and use some jquery to hide it when the document is ready and to show it when an event gets triggered. Please advise if I'm not understanding correctly... The code for the jquery will look like this: <script type="text/javascript"> $(document).ready(function() { $('#form').hide(); }); $(document).ready(function() { $('#button').click(function() { $('#form').show(); }); }); </script> This should work, let me know if nothing happens when you insert this code. If you don't have jquery yet, you can download it here: http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2.js&downloadBtn= Just insert the external js file in your original code As for the update of $qty, if you want it to update automatically, the best way I can think about without a refresh would be Ajax, if you are okay with the form causing a refresh then PHP would be sufficient Quote Link to comment Share on other sites More sharing options...
slaterino Posted January 5, 2010 Author Share Posted January 5, 2010 At the moment when the page loads, the $qty is not always correct (or rather the way I want it!). However, once I click the update button everything is exactly the way it should be. Therefore, I am just trying to find a way in which when the page loads up the 'update' can be run and everything will be perfect. This is why I was trying to find out if this is a way of doing this. Quote Link to comment Share on other sites More sharing options...
ChaosKnight Posted January 5, 2010 Share Posted January 5, 2010 Can you send all the code related to $qty? Sounds like there is a problem somewhere else with it Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 5, 2010 Share Posted January 5, 2010 If the $qty is not correct on the first page load, then there is a problem in how you are setting the value. You haven't provided any code to show how $qty is defined so it's difficult to provide any help. Quote Link to comment Share on other sites More sharing options...
slaterino Posted January 5, 2010 Author Share Posted January 5, 2010 Hey! Thanks so much for all your help on this! In the end I decided to do something ridiculously simple to resolve this. I just added one line into my code, if ($pricing == "Multi" && $qty == 1) {$qty = $multi1a;} Which basically meant that if the item was one of the items only available as a multiple item and the quantity was set as just '1' it would then be changed to $multi1a, which is the value of the minimum quantity. I really thought I was going to have to do something really complicated but seeing as this works I think I am quite happy to stick with this method! Thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.