---
title: "Calling JavaScript function in asp.net MVC"  
description: "Calling JavaScript function in asp.net MVC"  
author: "Anonymous User"  
published: 2011-10-11  
updated: 2011-10-11  
canonical: https://www.mindstick.com/forum/322/calling-javascript-function-in-asp-dot-net-mvc  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 1 minute  

---

# Calling JavaScript function in asp.net MVC

hi,

I want to call [java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming) [script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line) [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server) when I make my [control](https://www.mindstick.com/blog/197/asp-dot-net-repeater-control) by [inline](https://www.mindstick.com/interview/1012/describe-the-difference-between-inline-and-code-behind) [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) in mvc. Pls. help me.

Thanks.

## Replies

### Reply by Chris Anderson

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.


---

Original Source: https://www.mindstick.com/forum/322/calling-javascript-function-in-asp-dot-net-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
