Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi to all,
Here i want to add two textbox value using onkey function.

@Html.TextBoxFor(model => model.value1, new { @class = "form-control control-text " })


@Html.TextBoxFor(model => model.value2, new { @class = "form-control control-text " })


above is my two text box how to write script for above two text box and adding functionality.
Posted

1 solution

Hii,

you can add id attribute to both text boxes, then you can get their values in javascript or jQuery.

like,
HTML
@Html.TextBoxFor(model => model.value1, new { @class = "form-control control-text", @id= "txtBox1" })

and
HTML
@Html.TextBoxFor(model => model.value2, new { @class = "form-control control-text", @id= "txtBox2" })


Now in jQuery,
JavaScript
alert($('#txtBox1').val() + $('#txtBox2').val());
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 27-Nov-14 5:36am    
value should populate in text box but its only join not adding the value
For ex:
txtbox1=10
txtbox2=20
its just show 1020
Mathew Soji 27-Nov-14 5:39am    
try

alert(parseInt($('#txtBox1').val() +
parseInt($('#txtBox2').val() )
JOTHI KUMAR Member 10918227 27-Nov-14 5:47am    
hey i got it solution as per your idea bro

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900