It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

QTY / UNIT PRICE

QTY / UNIT PRICE

Postby creativeminds on Fri Oct 12, 2007 10:45 pm

Hi all,

I would like to create a 2 text boxes. The first text box will be the edit text box where I can enter in numbers. The second text box will display the dollar amount. Below are the qty and unit prices:

QTY --------- Unit Price

1-5------------$250

6-10-----------$225

11-15----------$200

16 and up-----$180


Let say I wanted to enter quantity of 8, it should calculate in the amount of $225.00 because it fall into that qty. If I enter quantity of 100, the price should show up in the second display box of $180.00. Can the price change immediately when entering the QTY or does the user have to refresh the browser? That would not be a very good tool than. It should chance the pricing right away when a user enter the quantity. Please create this so there are no decimal .00, I just need the dollar amount $245


One other thing, I would like for the edit text box to give an error or alert message "Please enter a valid number." when someone entering letters or strange characters. The text box should except numbers ONLY.

Here is what I have started:


Code: Select all
<html>


<body>

<script language="javascript">

function is_valid(text)
{
   var isValid = true;
   var validChars = "1234567890";
   var CharIndex;
   {
         if (valiChars.indexOf (text.CharAt (CharIndex).toLowerCase()) <0)
         {
            isValid = false;
         alert("Please enter a valid number.");
         
         break
      }
   }   

   return isValid;
}   
   
   
</script>

QTY <input type="text" name="textboxwidth" size="3" maxlength="1000">


Unit Price $ <input type="text" name="textboxwidth" size="8" maxlength="1000">


</body>
</html>




Thanks in advance!![/code]
creativeminds
 
Posts: 2
Joined: Fri Oct 12, 2007 10:28 pm

Postby dafunkymunky on Sun Oct 14, 2007 4:40 pm

<html>
<head>
<script language="javascript">

function col()
{

unit=parseInt(document.estimate.units.value)
if(unit>=0 && unit<=5)
{
document.estimate.unitprice.value="$250 "
}
else if(unit>5 && unit<=10)
{
document.estimate.unitprice.value="$225 "
}
else if(unit>10 && unit<=15)
{
document.estimate.unitprice.value="$200 "
}
else if(unit>=16)
{
document.estimate.unitprice.value="$180 "
}
}



</script>
</head>
<body>

<form name="estimate">
QTY <input type="text" name="units" size="3" maxlength="1000" onkeyup="col()">

Unit Price $ <input type="text" name="unitprice" size="8" maxlength="1000">
</form>

</body>
</html>



this should do.. But it doesnt take care of alphabet inputs..
--------DAFUNKYMUNKY--------
::THE::NECESSARY::[D]EVIL::
....errr i mean munky....
User avatar
dafunkymunky
100+ Club
 
Posts: 183
Joined: Fri Apr 08, 2005 7:32 am
Location: India

Postby creativeminds on Mon Oct 15, 2007 1:55 am

Thanks my friend!!

I will play around with the letters.
creativeminds
 
Posts: 2
Joined: Fri Oct 12, 2007 10:28 pm


Who is online

Users browsing this forum: No registered users and 6 guests