Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
I want to use asp.net control id in a separate js file which is called in footer as per html5 standards

how to use in other js file

for exp:
ASP.NET
<asp:TextBox ID="ToValue" Text="" class="autosuggest" runat="server"></asp:TextBox>


now i want to get ToValue.text value in separate js file where function for autocomplete is written

How to do this ???????? Pls advice

regards

maulik shah
Posted
v2

JavaScript
var toValue = document.getElementById('ToValue');
var textToValue = toValue.value;
 
Share this answer
 
Comments
maulikshah1990 2-Dec-13 2:08am    
thanks..one question i have is
how to define function in js file and call it from html code after including that js file in code
Write the following function in External js file.

function test()
{
alert("Hello World");
return false;
}

Now if you want to call this function from HTML page button click event, then do like below.

If asp button, then

<asp:Button ID="ButtonID" runat="server" onClientClick="return test();"></asp:Button>

If HTML Button, then use onclick event.
See this Link[^] may helps you

Thanks
--RA
 
Share this answer
 
Comments
maulikshah1990 2-Dec-13 2:10am    
thanks..but the link doesn't open
also
how to define function in js file and call it from html code after including that js file in code
Rajesh Anuhya 2-Dec-13 2:14am    
Code Behind:
ddl.Attributes.Add("onChange", "return OnFoodChange(this,'" + myTextBox[i].ClientID + "');");

HTML: JAVA Script
function OnFoodChange(myCmb,myTextBoxId) {
currentTextBox = document.getElementById(myTextBoxId);
//Your code...
}

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