Forum Moderators: coopster
<tr><td align="center">Quantity: <input type="text" size=2 maxlength=3 name="QUANTITY" onChange='this.value=CKquantity(this.value)' value="1" >
<input type="button" value=' Add to Cart ' onClick='AddToCart(this.form)' ></tr></td>
<input type="hidden" name="PRICE" value="<? echo $price; ?>" >
<input type="hidden" name="NAME" value="<? echo $choice; ?>" >
<input type="hidden" name="ID_NUM" value="<? echo 'Num_".$id."'; ?>" >
<?php
}//while
echo "</tr>";
echo "</table>";
=======================================================
thats the code, ive also tested <? echo "blah"; ?> within the html table and nothing echos.
It seems to get blocked by the html table row tags or something.
The table opening and closing tags are out side the while loop and are in php.
these $price variables needs to be in the html as shown in the code, its for a shopping cart im integrating, which need this html.
Any suggestions or help plz?
Thanks
rather than:
<? echo $price ?>
If that doesn't solve the issue, just wrap the whole thing into the php...
echo '<tr>';
echo '<input type="hidden" name="_id_'.$id.'" value="'.$id.'">' .
'<tr><td width="20%" align="center" colspan="4">' .
'<font size="3" color="#FF0000">$ '.$price.'</font></td>' .
'etc.';
NOTE: Switched to single-quotes so variables will not be expanded...
It makes concatenation necessary, but is IMO much easier to read / work with, and according to the benchmarking in the library, accumulation + concatenation is faster for parsing than expanding variable within quotes or switching in and out of html / php.
Personally, I store everything in a variable and echo it when the script is finished...
$table = '<tr>';
$table .= '<input type="hidden" name="_id_'.$id.'" value="'.$id.'">' .
'<tr><td width="20%" align="center" colspan="4">' .
'<font size="3" color="#FF0000">$ '.$price.'</font></td>' .
'etc.';
echo $table;
iNumberOrdered = 0; //Integer number of products already ordered
iNumberOrdered = GetCookie("NumberOrdered");
iNumberOrdered++;
if ( iNumberOrdered > 12 )
alert("I'm Sorry, your cart is full, please proceed to checkout.");
else {
dbUpdatedOrder = thisForm.QUANTITY.value + "¦"
+ thisForm.PRICE.value + "¦"
+ thisForm.ID_NUM.value + "¦"
+ thisForm.NAME.value;
NewOrder = "Order." + iNumberOrdered;
SetCookie (NewOrder, dbUpdatedOrder, null, "/");
SetCookie ("NumberOrdered", iNumberOrdered, null, "/");
notice = thisForm.QUANTITY.value + " "
+ thisForm.NAME.value
+ " added to your shopping cart.";
alert(notice);
}
}
------------------------------------------------------------
PHP:
<tr><td align="center">Quantity: <input type="text" size=2 maxlength=3 name="QUANTITY" onChange='this.value=CKquantity(this.value)' value="1" >
<input type="button" value=' Add to Order ' onClick='AddToCart(this.form)' >
<input type="hidden" name="PRICE" value=<?php echo $price ;?> >
<input type="hidden" name="NAME" value=<?php echo $choice ;?> >
<input type="hidden" name="ID_NUM" value=<?php echo "Num_".$id.""; ?> ></tr></td>
-----------------------------------------------------------
When i click on the Add to Order button, the JS alert says "undefined undefined added to cart."
where undefined should be $price (PRICE) and $choice.
Ive proved that $price and $choice (NAME) are loaded variables (working), however, its undefined in the JS.
I believe the JS is not liking the php $variables.
Am i correct to think this? if so, what can i do to feed the JS with these php dynamic variables?
Thanks for your help :)
<input type="hidden" name="PRICE" value=<?php echo $price ;?> >
<input type="hidden" name="NAME" value=<?php echo $choice ;?> >
<input type="hidden" name="ID_NUM" value=<?php echo "Num_".$id.""; ?> ></tr></td>
I think it should be:
<input type="hidden" name="PRICE" value="<?php echo $price ;?>" >
<input type="hidden" name="NAME" value="<?php echo $choice ;?>" >
<input type="hidden" name="ID_NUM" value="<?php echo "Num_".$id."";" ?> ></tr></td>
I might need some more detail, unless someone sees something else and this doesn't fix the issue...