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

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

techquesAsked:
Who is Participating?
 
HonorGodConnect With a Mentor Software EngineerCommented:
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
 
techquesAuthor Commented:
excellent!
0
 
HonorGodSoftware EngineerCommented:
I'm happy to have been able to help.  Thanks for the grade & points.

Good luck & have a great day.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.