Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Banned
    Join Date
    Jan 2012
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Generic way to execute JavaScript

    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:
    Code:
    <SCRIPT type="text/javascript">
    	if (document.forms["form"]["quantitym"].value > '.$row['sizem'].') {
    		alert ("The quantity for product $row['id'] is no longer available.");
    	}
    </SCRIPT>
    
    <FORM action="updatecart.html" method="post" name="form">
    	<DIV>
    		<B>Medium:</B> <INPUT name="quantitym" value="'.$content['sizem'].'">
    	</DIV>
    </FORM>
    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?
    Last edited by FlashDancer; 01-20-2012 at 07:01 AM.

  • #2
    Banned
    Join Date
    Jan 2012
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts
    The problem was that I treated JavaScripts parsing as PHP. The Script should be after the INPUT.

    Solved.

  • #3
    Banned
    Join Date
    Jan 2012
    Posts
    26
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Double.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •