/    Sign up×
Community /Pin to ProfileBookmark

cookies+form help please

If I have the below code to allow users to enter a quantity of an item, how would I go about setting what the user enters into a cookie, with a value of id, name, description, quantity per item the enter a quantity for and press the submit button? Also, can I use the onclick=”return false;” to the page does not reload every time a users presses the submit button for each item they want? And, once the cookie has the values for each item, how would I go about reading those values from the cookie to display on a separate page?

[code]
<form name=”orderList” class=”products” action=”<?=$_SERVER[‘PHP_SELF’];?>”>
<p>
<strong>Price: $<?=$price;?> ea.</strong>
</p>
<p>
<strong>Min. Qty: </strong><?=$min_qty;?>
</p>
<p>
<span style=”float:left; width:25px;”>Qty:</span> <span style=”float:right;width:135px;”><input type=”text” name=”item_qty_ordered” id=”item_qty_ordered” class=”qtyOrdered” value=”<?=$item_qty_ordered;?>” /></span>
</p>
<p style=”display:none;”>
<input type=”hidden” name=”item_id” id=”item_id” value=”<?=$id;?>” />
<input type=”hidden” name=”item_name” id=”item_name” value=”<?=$name;?>” />
<input type=”hidden” name=”item_price” id=”item_price” value=”<?=$price;?>” />
</p>
<p>
<input type=”submit” name=”submit” value=”Add to Order” onclick=”return false;” class=”button” />
</p>
</form>
[/code]

Thanks!!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@jrthor2authorNov 09.2007 — Ok, here is some updated code, but this is only using javascript to make sure they entered something in the quantity box, and shows a message that the item was added to the order. How would I go about actually adding what the clicked on to a cookie, or session variable I guess, but I've read the cookies would be better.

code fore each item:
<i>
</i>&lt;form name="orderList" class="products" action="&lt;?=$_SERVER['PHP_SELF'];?&gt;" method="post" onsubmit="return checkProduct(&lt;?=$min_qty?&gt;, document.getElementById('item_qty_ordered:&lt;?=$id?&gt;').value, '&lt;?=$name?&gt;');"&gt;
&lt;p&gt;
&lt;strong&gt;Price: $&lt;?=$price;?&gt; ea.&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Min. Qty: &lt;/strong&gt;&lt;?=$min_qty;?&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;span class="qtyLabel"&gt;Qty:&lt;/span&gt; &lt;span class="qtyInput"&gt;&lt;input type="text" name="item_qty_ordered" id="item_qty_ordered:&lt;?=$id;?&gt;" class="qtyOrdered" value="&lt;?=$item_qty_ordered;?&gt;" /&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="display:none;"&gt;
&lt;input type="hidden" name="item_id" value="&lt;?=$id;?&gt;" /&gt;
&lt;input type="hidden" name="item_name" value="&lt;?=$name;?&gt;" /&gt;
&lt;input type="hidden" name="item_price" value="&lt;?=$price;?&gt;" /&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;input type="submit" name="submit" value="Add to Order" class="button" /&gt;
&lt;/p&gt;
&lt;/form&gt;

I just noticed a problem. I have multiple items on a page. If I enter a quantity for 1 of the items, when the page refreshes, that quantity is in all my quantity input boxes. How can I fix this?

Thanks
×

Success!

Help @jrthor2 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...