Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/187271-form-to-load-automatically/
Share on other sites

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

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.

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.