problem in getting the value

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
purnendu231172
Forum Newbie
Posts: 11
Joined: Mon Apr 16, 2007 6:29 am

problem in getting the value

Post by purnendu231172 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi all

I am getting the problem in displaying the value. once i select quentity one, the cost should be 9.95. once i will select the quentity as 2 , the cost sould be 19.90. once i select 3, cost should be 29.85. I am getting the value.
          But the problem is that , i want to select quentity as 2, the value shoud come 19.90 but infact it is coming 19.9 only.

                          
[syntax="html"]<script>function changePrice()
{
	//document.f1.selectQty.value
//document.f1.price.value=Math.round((document.f1.selectQty.value*9.95)*100)/100;
document.f1.price.value=Math.abs((document.f1.selectQty.value*9.95)*100)/100;
}

</script>


<table width="100%" border="0" cellpadding="6" cellspacing="0" bgcolor="#F3F5FC" class="blueborder">
<form name="f1" method="post" onSubmit="return validate();" >
                  <tr> 
					  <td width="47%" align="left" valign="middle"><H3>Tuxedo 
                    Blue Diamond Prepaid Maestro Card </H3></td>
                    <td width="31%" align="center" valign="middle"><H3>Quantity: 
                        <select name="selectQty" id="selectQty" onChange="changePrice();">
                          <option value="1" selected>1</option>
                          <option value="2">2</option>
                          <option value="3">3</option>
                        </select>
                    </H3></td>
                    <td width="22%" align="right" valign="middle"><h3><span class="div-align"> 
                        Cost:&nbsp;<span class="style1">&pound;</span> 
                        <input name="price" class="form" 
                  id="price" value="9.95" size="8" />
                        </span></h3></td>
                  </tr>
</form>
                </table>


	<script>function changePrice()
{
	//document.f1.selectQty.value
//document.f1.price.value=Math.round((document.f1.selectQty.value*9.95)*100)/100;
document.f1.price.value=Math.abs((document.f1.selectQty.value*9.95)*100)/100;
}

</script>
please give me the solution, It is urgent.

Thanks & Regards

Ranjan


feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
veridicus
Forum Commoner
Posts: 86
Joined: Fri Feb 23, 2007 9:16 am

Post by veridicus »

As long as it's calculating correctly all you have left to do is format the number for display.

A quick google search found this: http://www.mredkj.com/javascript/numberFormat.html
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

This question appears to not be about PHP. Moved to Client-side.
Post Reply