Home > DeveloperSection > Forums > Calling JavaScript function in asp.net MVC
Carl Pieterson
Carl Pieterson

Total Post:14

Points:98
Posted on    October-11-2011 3:07 AM

 ASP.NET MVC ASP.NET MVC 
Ratings:


 1 Reply(s)
 9665  View(s)
Rate this:

hi,

I want to call java script function when I make my control by inline code in mvc. Pls. help me.

Thanks.



Chris Anderson
Chris Anderson

Total Post:65

Points:455
Posted on    October-11-2011 3:14 AM

hello,

First create a java script function-->

        <script type="text/javascript">
            function selectedIndexChanged() {
                       alert("Hello");   
            }
            function ontextChanged(){
                        alert("Hello")
           }
        </script>

Then call that function by using control which is made by inline code, as below:

<%:Html.DropDownListFor(x => x.SelectedProduct, new SelectList(Model.Products, "Value", "Text"), "Please Select a product", new { id = "dropDown1", onchange="selectedIndexChanged()" })%>

<%:Html.TextBoxFor(x => x.Name,new {id="txtName",onkeypress="ontextChanged()" })%>

Try it. This will help you.

Don't want to miss updates? Please click the below button!

Follow MindStick