Hey

is there a way of automaticly submitting my form when the page is loaded.

the form code is

$self = $_SERVER['PHP_SELF'];

<form name="myform" action="<?php $self; ?>" method="post">
stuff
<?form>

my site is a book store, when a user clicks the buy it automaticly calculates the cost but only when i click the submit button, i want it to automaticly calculate the cost when the user cklicks buy. the initial value of the text box is 1 but the user can enet another value and click update this will then recalculate the total cost.

to make things a little clearer

a customer buy say harry potter and it costs £5 if the they click buy it takes them to a page where it shows the total cost so the default value will be £5 (text box is 1) but this only calculates when i click the button if i change the value in the text box to 2 and click submit the cost will be £10.

i hope this is clear, basicly i just want the form to automaticly submit on load, remember i am using the php_self so it runs on the same script.

cheers

john

any help would be apriciated (this is an assignment for uni)

    Sounds like you need to look into AJAX.
    I haven't done AJAX myself yet, but have been looking into it .

    Sounds like what you need.

    Or you can write some javascript to handle the calculations.

      This may be overly obvious but to submit the form when the page loads:

      <script>
      function submitMyForm() {
      document.myform.submit();
      }
      </script>

      <body onload="submitMyForm()">

        If you are looking for the form to update total cost etc each time the user makes a change on the order form, you need to use the javascript onChange function. A search on google should find you plenty of information.

        Blu

          It doesn't sound like you want it done when the page loads, because then the user won't have a chance to do anything - you'll just get back whatever was in the form when you served it in the first place.

          You also don't want to rely on the form calculating any part of the costing. Use Javascript to update those quantities for the user's benefit, by all means, but recalculate them yourself when you receive the submitted form. If you trust what the users say the total cost is, before too long they'll be saying that it's free.

            Write a Reply...