NYCPHP Meetup

NYPHP.org

[nycphp-talk] Can this be done with PHP or JavaScript? Is it even possible?

Jim Hendricks jim at bizcomputinginc.com
Sat Jul 20 17:21:23 EDT 2002


Where is the problem with passing all the items?  If $submit == "submit1"
then use $item1 and $amount1 if $submit =="submit2" then use $item2 and
$amount2.

Based on your example also, couldn't item & amount be put into a table &
based on which button the user pushes determines which record to look up to
populate item and amount?

If you can't do all this on the server, then JS looks the way to go.  I
would still use 1 form, except the submit button would call a JS user
function passing the 2 values.  The function would then take the 2 values
and put them in the fields.  So long as the button is a submit, the submit
will happen after the JS user function.  Look at below example.  I just
typed this off the top of my head, so if it doesn't work, you'll know why.
Hopefully it gives you the idea though.

Jim

<p>STEP 1. ENTER YOUR DOMAIN NAME:
<form action="https://domain.com/cgi-bin/webscr" method="post" name="form1">
<input type="hidden" name="OptionName" value="Domain">
<input type="text" name="OptionValue" size="25"></p>

 <p>STEP 2. CHOOSE A PLAN:</p>
<p>PLAN A 3 MONTHS
<input type="hidden" name="item">
<input type="hidden" name="amount">
<input type="submit" name="submit" onClick="setValues( 'PA03',
'74.85' );"></p>
<p>PLAN A 6 MONTHS
<input type="submit" name="submit" onClick="setValues( 'PA06',
'137.70' );"></p>
<p>PLAN A 12 MONTHS
<input type="submit" name="submit" onClick="setValues( 'PA12',
'239.40' );"></p>
</form>

<script language="javascript">

function setValues( asItem, asAmount ) {
  document.form1.item.value = asItem ;
  document.form1.amount.value = asAmount ;
}

</script>


----- Original Message -----
From: "SolTek" <soltek at mac.com>
To: "NYPHP Talk" <talk at nyphp.org>
Sent: Saturday, July 20, 2002 4:56 PM
Subject: Re: [nycphp-talk] Can this be done with PHP or JavaScript? Is it
even possible?


> Thanks for the advice Jim, but when a button is clicked I need only one
> of the hidden "item" and one of the hidden "amount" values to be passed
> to the cart.
>
> Thanks,
> Steve
>
> On Saturday, July 20, 2002, at 11:53 AM, Jim Hendricks wrote:
>
> > As far as I know, the only way to get data outside a form to be sent
> > with
> > the request
> > would be the use of JS either to build it as part of the querystring,
> > or to
> > finagle some
> > form elements.
> >
> > But, based on what you have below, I don't see that you need all those
> > forms, why not
> > just one form.  If it's a matter of determining which submit button the
> > user
> > chose, then
> > give each submit button a different value, the selected button's value
> > would
> > be associated
> > with the button field item available on the server side which would
> > then let
> > you know
> > which of your hidden fields to use.  For example:
> >
> > <p>STEP 1. ENTER YOUR DOMAIN NAME:
> > <form action="https://domain.com/cgi-bin/webscr" method="post">
> > <input type="hidden" name="OptionName" value="Domain">
> > <input type="text" name="OptionValue" size="25"></p>
> >
> >  <p>STEP 2. CHOOSE A PLAN:</p>
> > <p>PLAN A 3 MONTHS
> > <input type="hidden" name="item1" value="PA03">
> > <input type="hidden" name="amount1" value="74.85">
> > <input type="submit" name="submit" value="submit1"></p>
> >
> > <p>PLAN A 6 MONTHS
> > <input type="hidden" name="item2" value="PA06">
> > <input type="hidden" name="amount2" value="137.70">
> > <input type="submit" name="submit" value="submit2"></p>
> >
> > <p>PLAN A 12 MONTHS
> > <input type="hidden" name="item3" value="PA12">
> > <input type="hidden" name="amount3" value="239.40">
> > <input type="submit" name="submit" value="submit3"></p>
> > </form>
> >
> > ----- Original Message -----
> > From: "SolTek" <soltek at mac.com>
> > To: "NYPHP Talk" <talk at nyphp.org>
> > Sent: Friday, July 19, 2002 8:58 PM
> > Subject: Re: [nycphp-talk] Can this be done with PHP or JavaScript? Is it
> > even possible?
> >
> >
> >> Sorry to stir up such a debate earlier, but I still do need help. :-)
> >> Maybe someone can assist me. I'm actually just learning PHP and was
> >> hoping to concentrate on that before learning anything else. But it
> >> seems I may not have a choice.
> >>
> >> I'm thinking this can only be done with JavaScript, but maybe I'm
> >> wrong.
> >>
> >> Is there a way I can get form values that are on the same html page
> >> as a
> >> form but outside of the form tags, and then pass them along with the
> >> rest of a forms values when a submit button of a form is clicked? The
> >> page must contain multiple forms. Each form will contain different
> >> hidden values and a submit button.  The form values outside of the form
> >> tags will be associated with every form on the page which is why they
> >> must also be sent along with the rest of the particular form's hidden
> >> values.  To help illustrate this I've included and commented the HTML
> >> code I'm using below.
> >>
> >> Many thanks to anyone who could help out!
> >> - Steve
> >>
> >>
> >>
> >>
> >>
> >>
> >
> >
> >
>
>
>
>
>





More information about the talk mailing list