We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Setting the value using javascript after initialisation

I have declared a numeric text box in my markup:

<ej:NumericTextBox ID="ntbTotal" runat="server" MinValue="0" WatermarkText="" 
                                        ReadOnly="true" CssClass="stock-open-total" ShowSpinButton="false" />

I want to access the textbox in javascript and update the value as a sum of other numeric text boxes with the class "stock-open-val".

So far I have come up with the code below. Getting the values works fine however I haven't found a way to select the total numeric text box and update the value.

function stockOpeningCalc(inst, args) {
    var openValTBs = $(".stock-open-val .e-numerictextbox");

    var openTotal = 0;

    for (var i = 0; i < openValTBs.length; i++)
    {
        var value = openValTBs[i]["value"];
        if ($.isNumeric(value)) openTotal += parseFloat(value);
    }

    //set value here
}

1 Reply

AB Ashokkumar Balasubramanian Syncfusion Team July 26, 2016 11:08 AM UTC

Hi Lewis, 
 
Thanks for using Syncfusion Products. 
 
We have analyzed your requirement (“To set the Value to Numeric Textbox”).We can use the Value property to set the value for textbox control. 
 
Please refer the below code. 
[JAVASCRIPT] 
function myFunction(inst,args) { 
        var openValTBs = $(".stock-open-val .e-numerictextbox"); 
 
        var openTotal = 0; 
 
        for (var i = 0; i < openValTBs.length; i++) 
        { 
            var value = openValTBs[i]["value"]; 
            if ($.isNumeric(value)) openTotal += parseFloat(value); 
        } 
        $("#ntbTotal").ejNumericTextbox("instance").option({ value: openTotal }); 
} 
 
As per requirement, we have prepared a sample and the sample can be downloaded from the following location. 
Sample Location: Textboxes 
 
To know more about the api configuration, please refer the below link. 
 
Please let us know whether the provided sample is helpful in achieving your requirement or not. If you have any other queries, please get back to us with additional information, we will happy to assist you.  
 
Regards, 
Ashokkumar B

Loader.
Live Chat Icon For mobile
Up arrow icon