0

I have two text boxes on my Form. One is txtNumberOfTablets and the other one is txtTotalQuantity.

I have a HiddenField and I am setting its value in code behind file on page load.

hdfMedicationDosage = "2/3/4";

What I want is, whatever user enters to txtNumberOfTablets textbox, should be multiplied with hdfMedicationDosage value when focus is out of txtNumberOfTablets.

For example txtNumberOfTablets contains value 2, and focus is out of txtNumberOfTablets, then that txtTotalQuantity will have a value 2*2/3*2/4*2 i.e.4/6/8

I want to achieve this in JavaScript.

4
  • How much dollars, you will pay us for this assignment ? :) You should provide your code what you have tried so far. Commented Aug 26, 2011 at 10:39
  • LOL I haven't tried anything yet because I have a lot work to do :( I'll try soon and then will edit my question. Commented Aug 26, 2011 at 10:42
  • You can share some work with us, so your burden will be less :) Commented Aug 26, 2011 at 10:44
  • For that, I will have to give a longggg description for you to get the domain understanding :-s Commented Aug 26, 2011 at 10:46

2 Answers 2

1

You should create a function that takes the string value in hdfMedicationDosage and uses the string.split() method to get an array of the numbers as strings. Then just iterate through the array and convert each string using Number before doing each multiplication. You can then concatenate the values back together as strings to populate txtTotalQuantity.

Sign up to request clarification or add additional context in comments.

Comments

1

You can see this fiddle for a way to do this.

$(document).ready(function(){
    var theValue = "2/3/4", multiplier = '2', newArray=[], valArray;

    valArray = theValue.split('/');

    for(var i=0;i<valArray.length;i++){
        newArray.push(valArray[i] * multiplier);
    }

    var newValue = newArray.join('/');

    $("#result").text(newValue);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.