View Full Version : Generic way to execute JavaScript

01-20-2012, 07:36 AM
I am wondering if its possible to execute a JavaScript script as soon as the page is loaded? Perhaps a generic execution?
I tried this, but it didn't work:

<SCRIPT type="text/javascript">
if (document.forms["form"]["quantitym"].value > '.$row['sizem'].') {
alert ("The quantity for product $row['id'] is no longer available.");

<FORM action="updatecart.html" method="post" name="form">
<B>Medium:</B> <INPUT name="quantitym" value="'.$content['sizem'].'">

This is for my shopping cart system. The idea is, the customer might have 4 items in his cart, but whilst he was shopping, someone might of bought the same item, result in only 3 being available, but his cart still says 4.

My solution to this is to make a script run through out his shopping when ever the cart items are listed and just prior payment execution, if the quantity he wants is no longer available, he will be alerted.

$row['sizem'] is PHP drawing how many items there are from my stock database. If the value of the INPUT exceeds this availability, JavaScript shall alert.

Does anyone know why it isn't alerting?

01-20-2012, 08:03 AM
The problem was that I treated JavaScripts parsing as PHP. The Script should be after the INPUT.


01-20-2012, 08:20 AM