Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
My dropdown combobox has many values like

'Is'
'Is Not'
'Between'

I want to call a clientside Javascript function on selection of 'Between' option. How do I do it ?
What should I do in the .cs page to call the method ?

I have added the below code to register the control I want to use. Now how do I call the function in JS when its value is changed ?

Page.ClientScript.RegisterStartupScript(this.GetType(), "GetTextBoxForBetween", "var cboGLSubTransactionType = '" + cboGLSubTransactionType.ClientID + @"'", true);
Posted
Comments
Rahul_Pandit 19-Nov-13 9:44am    
You can use it on selectedindex_changed at server side
Sergey Alexandrovich Kryukov 19-Nov-13 10:49am    
You never ever call JavaScript from .cs page. JavaScript is on client side, .cs on server side.
Server side can only generate script or call parameters, and the JavaScript method can be called, say, when a document is ready.
—SA
anglo0072 19-Nov-13 16:40pm    
are you trying to call a registered javascript function from code behind to js?
well whenever we have to call javascript function we have to register it on codebehind as you did it
and whenever we have to pass a value from code behind to js we need to create a webservice and then call this webservice by using Ajax Post method

hi check the below code

C#
dropdownost1.Attributes.Add("onchange","javascript:yourjsfunction()");
 
Share this answer
 
Hi,


just add
HTML
onchange="javascript:yourfunc();"
at your Html

and in javascript
JavaScript
funnction yourfunc()
{
//Please add Jquery 
var val=$('Id').val();
if(val=="Between")
{
// your code
}
}
 
Share this answer
 
at client side



function GetCombobox(value)
{
var dropvalue = document.getElementById(value)
alert(dropvalue);
}




then in .cs page at SelectedIndexChanged event write this code

drpdownlist.Attributes.Add("OnChange","javascript:Getcombobox('"+drpdownlist.ClienId+"')")
 
Share this answer
 
in cs fill on change event of dropdown list call your java script function on this way:-

ScriptManager.RegisterStartupScript(Page, this.GetType(), "CallJS", "JSFunctionName();", true);

and in your form write your java script function.


function JSFunctionName() {

alert("1");
}
 
Share this answer
 

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