Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2006
    Location
    Johannesburg,South Africa
    Posts
    598

    some javascript help needed please

    Hi all

    I have a strange problem with a simple piece of javascript, and I don't know why it' behaving like it is.

    I need to dispence stock to a client, but the stock is allocated to certain batches, and I don't want the user to allocate more stock than a particular batch has. Here's the script:

    Code:
    	if(stock < qty) {  
    		alert("You can't prescribe more items than currently in stock for this batch. The current allowable limit is "+stock+"..    Please prescribe more items from the next batch.");
    
    	alert("qty value "+qty+ " :: stock value "+stock);
    
    		document.addform.qty_dispensed.focus();
    		return false;
    	}
    So, let's say stock = 2500, and qty = 300, then the argument should be valid, but it gives me an error. I've playd around with various combinations, and come to the following conclusion:

    The script above only reads the 1st bit of the value. So, on stock=2500 & qty = 100, the script goes through, but on stock = 2500 & qty = 300, it gives an error. It even gives an error if qty=3 / 4 / 6 / 40 / 500 / etc. But, 1 / 10 / 14 / 125 / etc works fine.

    Here's a full working sample:



    HTML Code:
    <SCRIPT LANGUAGE="javascript" TYPE="text/javascript">
    <!--
    function CheckQTY(){
    	var qty=document.addform.qty_dispensed.value;
    	var stock=document.addform.stock_qty.value;
    	
    	if(stock < qty) {  
    		alert("You can't prescribe more items than currently in stock for this batch. The current allowable limit is "+stock+"..    Please prescribe more items from the next batch.");
    
    	alert("qty value "+qty+ " :: stock value "+stock);
    
    		document.addform.qty_dispensed.focus();
    		return false;
    	}
    		// This is just a test to see what the values are. Please disable / remove this line for production purposes
    		alert("qty value "+qty+ " :: stock value "+stock);
    }
    
    //-->
    </SCRIPT>
    
    
    
    
    
    
    <FORM ACTION="" METHOD="POST" NAME="addform"  onSubmit='return CheckQTY(); submitonce(this);'>
    
    
    <INPUT TYPE="hidden" NAME="aid" VALUE="<?=$_REQUEST['aid'];?>">
    <INPUT TYPE="hidden" NAME="stock_id" ID="stock_id" VALUE="">
    
    <INPUT TYPE="hidden" NAME="patient_id" ID="patient_id" VALUE="<?=$_REQUEST['patient_id']?>">
    <INPUT TYPE="hidden" NAME="item_id" ID="item_id" VALUE="">
    
    <TABLE WIDTH=100% BORDER=0 ALIGN=center CELLSPACING=0 CELLPADDING=0>
    <TR CLASS=formSecHeader>
    <TH NOWRAP WIDTH=8%><DIV ALIGN=center><FONT SIZE=2><STRONG>Qty in Stock</STRONG></FONT></DIV></TH>
    <TH NOWRAP WIDTH=8%><DIV ALIGN=center><FONT SIZE=2><STRONG>Qty</STRONG></FONT></DIV></TH>
    </TR>
    <TR>
    <TD ALIGN=center><b><font color="#FF0000" ><input type="text" name="stock_qty" id="stock_qty" size="7" onChange="CheckQTY();" onClick="CheckQTY();" value="2500"></font></b></TD>
    <TD ALIGN=center><input type="text" name="qty_dispensed" id="qty_dispensed" size="7" onChange="CheckQTY();" onClick="CheckQTY();"></TD>
    </TABLE>
    <div id="debug_qty"></div>
    <div id="debug_stock"></div>
    <TABLE WIDTH="100%" BORDER="0" CELLPADDING="2" CELLSPACING="1">
    	<TR VALIGN="baseline">
    		<TD ALIGN="center" ><INPUT NAME="prescribe" CLASS="button" TYPE="submit" VALUE="Order"> &nbsp; 
    		<INPUT TYPE=submit CLASS=button NAME=stock VALUE="Cancel"></TD> 
        </TR>
    </TABLE>
    
    <SCRIPT LANGUAGE="JavaScript"><!--
            document.addform.qty_dispensed.focus();
    //--></SCRIPT>
    South African Web Hosting - http://www.SoftDux.co.za || SA WebHostingTalk - http://www.webhostingtalk.co.za

  2. #2
    Join Date
    Apr 2005
    Location
    Cochin
    Posts
    2,446
    I suggest you try the programming forum as well
    Sam
    Supportlobby.com - Expertise in Windows/Linux server support, IaaS and PaaS Management
    Spiralbean.com - Custom Software Development
    Email: exec @ activelobby.net | Skype: unni_active

  3. #3
    Join Date
    Oct 2002
    Location
    State of Disbelief
    Posts
    22,951
    Moved it there instead.
    Having problems, or maybe questions about WHT? Head over to the help desk!

  4. #4
    Join Date
    Apr 2005
    Location
    Cochin
    Posts
    2,446
    lol..missed that possibility
    Sam
    Supportlobby.com - Expertise in Windows/Linux server support, IaaS and PaaS Management
    Spiralbean.com - Custom Software Development
    Email: exec @ activelobby.net | Skype: unni_active

  5. #5
    Join Date
    Sep 2004
    Location
    Flint, Michigan
    Posts
    5,765
    Try:

    Code:
    function CheckQTY(){
    	var qty=document.addform.qty_dispensed.value;
    	var stock=document.addform.stock_qty.value;
    	
    	if(Number(stock) < Number(qty)) {  
    		alert("You can't prescribe more items than currently in stock for this batch. The current allowable limit is "+stock+"..    Please prescribe more items from the next batch.");
    
    	alert("qty value "+qty+ " :: stock value "+stock);
    
    		document.addform.qty_dispensed.focus();
    		return false;
    	}
    		// This is just a test to see what the values are. Please disable / remove this line for production purposes
    		alert("qty value "+qty+ " :: stock value "+stock);
    }
    Mike from Zoodia.com
    Professional web design and development services.
    In need of a fresh hosting design? See what premade designs we have in stock!
    Web design tips, tricks, and more at MichaelPruitt.com

Posting Permissions

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