Solved

How js multiply 2 text boxes values and display it on another text box?

Posted on 2009-04-09
3
461 Views
Last Modified: 2012-06-27
Hi

I use aspx and xml to create a listinput form with multiple rows.

There are 3 textbox in the aspx form.
rate, amount, countervalue

when i input 0.9, 1000, it can display countervalue = 900 automatically by the following js

function Calc(obj)
{
var objRec = xmlindata.recordset;                  
objRec.absolutePosition= obj.recordNumber;
objRec.Fields("countervalue").value = objRec.Fields("amount").value*objRec.Fields("rate").value;
}

however, when i input 1/0.9, 1000, it has error.

as the rate may be direct 0.9 or indirect 1/0.9

how can i fix it?
xml:

<column>

		<visible>1</visible>

		<sortable>0</sortable>

		<description>Rate</description>

		<prop>rate</prop>

		<type>textinput</type>

		<header>

			<title>Rate</title>

			<style

				style="cursor:default"

				class="list_title"

				/>

		</header>

		<cell>

			<style

				align="center"

				class="clsLVTDText"

				/>

		</cell>

		<textinput>

			<style

				style="width:90%"

				class="form"

				id="rate"

				maxlength="8"

				onblur="Calc(this)" 

				/>

		</textinput>

	</column>

	

	<column>

		<visible>1</visible>

		<sortable>1</sortable>

		<description>Amount</description>

		<prop>amount</prop>

		<type>textinput</type>

		<header>

			<title>Amount</title>

			<style

				style="curosr:default"

				class="list_title"

				/>

		</header>

		<cell>

			<style

				class="clsLVTDText"

				/>

		</cell>

		<textinput>

			<style

				style="width:90%"

				class="form"

				id="amount"

				onblur="Calc(this)" 

				/>

		</textinput>

	</column>		
 

		<column>

		<visible>1</visible>

		<sortable>1</sortable>

		<description>countervalue</description>

		<prop>countervalue</prop>

		<type>textinput</type>

		<header>

			<title>Counter Value</title>

			<style

				style="cursor:default"

				class="list_title"

				/>

		</header>

		<cell>

			<style

				align="center"

				class="clsLVTDText"

				/>

		</cell>

		<textinput>

			<style

				style="width:90%"

				class="form"

				id="countervalue"				

				/>

		</textinput>

	</column>

Open in new window

0
Comment
Question by:techques
  • 2
3 Comments
 
LVL 41

Accepted Solution

by:
HonorGod earned 50 total points
ID: 24108493
Yes.
The problem is that 1/0.9 is an expression that needs to be evaluated.

So, you will need to do something like:
function Calc(obj) {

  var objRec = xmlindata.recordset;

  if ( objRec ) {

    objRec.absolutePosition = obj.recordNumber;

    var amountVal = eval( objRec.Fields("amount").value )

    var rateVal   = eval( objRec.Fields("rate").value )

    objRec.Fields("countervalue").value = amountVal * rateVal

  }

}

Open in new window

0
 

Author Closing Comment

by:techques
ID: 31568576
excellent!
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24108704
I'm happy to have been able to help.  Thanks for the grade & points.

Good luck & have a great day.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now