I have a method that calls another method (on ajax load, but that’s irrelevant for this question). I’d like to pass parameters to this method. How is this possible?
The below page should scroll to id 25 on button click (the scrollable area is dynamically added in codebehind. this is just an example of what I’m attempting to accomplish)
JS
<%@ Page Language="C#" Inherits="APTEIT.scrolltest" %>
<html>
<head>
</head>
<body>
<script type="text/javascript">
function callHandler(handler) {
handler();
}
function scroll(id) {
alert("scrolling");
$("#divy").scrollTop($("#"+id).position().top);
}
</script>
<input type="button" value="scroll" onclick='var scroll={param1: "25"};callHandler(scroll)' />
</body>
</html>
You don’t seem to pass the parameter into the handler in the
callHandlermethod – instead, you try to invoke thescrollparameter (which isvar scroll={param1: "25"}) as a function.You use the same name
scrollboth for a config object and a function name. Please use different names 🙂 Moreover, your declared and used function signatures do not agree. Thescrollfunction accepts a stringidwhile you are trying to pass in an object instead.