Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-20-2012, 06:36 AM   PM User | #1
FlashDancer
Banned

 
Join Date: Jan 2012
Posts: 26
Thanks: 4
Thanked 0 Times in 0 Posts
FlashDancer is an unknown quantity at this point
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..
FlashDancer is offline   Reply With Quote
Old 01-20-2012, 07:03 AM   PM User | #2
FlashDancer
Banned

 
Join Date: Jan 2012
Posts: 26
Thanks: 4
Thanked 0 Times in 0 Posts
FlashDancer is an unknown quantity at this point
The problem was that I treated JavaScripts parsing as PHP. The Script should be after the INPUT.

Solved.
FlashDancer is offline   Reply With Quote
Old 01-20-2012, 07:20 AM   PM User | #3
FlashDancer
Banned

 
Join Date: Jan 2012
Posts: 26
Thanks: 4
Thanked 0 Times in 0 Posts
FlashDancer is an unknown quantity at this point
Double.
FlashDancer is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:14 PM.


Advertisement
Log in to turn off these ads.