How can I bind event handlers in Telerik MVC ClientTemplates? - javascript

I'm trying to call a function with arguments from Telerik grid ClientTemplate, like this:
.ClientTemplate("<a href=\"javascript:OnModifyDescription('<#= Value1 #>');\" title='Modify'>...</a>")
When the Value argument contains a single quote then on clicking the link results in the error: "Uncaught SyntaxError: Unexpected identifier".
What is the correct way to bind a function in a ClientTemplate?
Thanks in advance.

Make your client template as this :
.ClientTemplate("<a class='MyClass' myAttrib='<#= Value1 #>') title='Modify'>...</a>")
Then write the following scripts at top of your page:
<script>
$('a.MyClass').live('click',function(){
var myVal = $(this).attr('myAttrib');
OnModifyDescription(myVal);
});
</script>
Check this for jquery live function : http://api.jquery.com/live/

Related

getting dropdown selected value using DOJO

I need to get a selected value using dojo, from the dropdown without redirecting to another page.
I have tried something like this:
dojo.addOnLoad( function() {
dojo.connect(dojo.byId('#inquiry_type'), "onchange", function(evt) {
alert("changed!");
console.log("option Changed to: "+evt.target.value);
dojo.stopEvent(evt);
});
});
Above code gave me undefined in console. Can anyone help me with dojo code?
Omit the # in your call to dojo.byId. It just needs the name. Using the # syntax is what you would do with dojo/query.

Uncaught TypeError: undefined is not a function - jQuery

I have problem with website slide. after clicking on inspect element in chrome i get massage
"Uncaught TypeError: undefined is not a function" in file custom.js
here is file code
jQuery(document).ready(function() {
jQuery('#slider').nivoSlider({pauseTime: 4500}); });
}
here is website address http://myisraeltoday.com using WordPress
Theme: http://wordpress.org/themes/effect
Help needed
That means that you're calling something as a function (or method), when in fact it doesn't exist. You're calling three functions:
jQuery
jQuery(document).ready
jQuery('#slider').nivoSlider
The third of these is most likely the problem.
try changing your code to this :
$(document).ready(function() {
$('#slider').nivoSlider({'pauseTime': 4500});
});
PS : Note the }); at the end not just the $

Mixitup - Uncaught TypeError: Cannot read property 'left' of undefined

Using default mixitup configuration $('#id').mixitup(), I am adding a filter button dynamically by appending html code for button <li> tag. And calling the same function again instantly after adding html code to the page, in order to make the new button work. After clicking some filter buttons on the page (even if I don't press the new one) animation effects break and on the browser console I see:
Uncaught TypeError: Cannot read property 'left' of undefined error.
The error occurs on line 937:
$toshow.each(function () {
var data = this.data;
data.tX = data.finalPos.left - data.showInterPos.left; //HERE
I saw on documentation how to add new images to the list by using jquery after method, but there are no explanations about how to dynamically add filter buttons and initialize them on the fly.
Is the described behaviour expected?
That means I am doing something wrong. Then, how to initialize the new filter button correctly?
I am using Mixitup 1.5.6 (latest) with jQuery 1.10.2 (Also tried with jQuery 2.0.3).
Thanks in advance!
Your problem is that either data.finalPos or data.showInterPos is undefined. console.log data after you define it to see if you even have those keys
$toshow.each(function () {
var data = this.data;
console.log(data); //here
data.tX = data.finalPos.left - data.showInterPos.left;

Undefined variable error that shouldn't be a variable

I've made a piece of code in jquery that assigns a href attribute to a variable. Here's that code:
$('#reactions' + i).attr('href', 'javascript:comments ('+entry.url+','+i+');');
This should assign a call to the javascript function comments. Now I want to use that call on a jquery mobile button, like this:
document.write('Reactions');
But doing this gives me a in FF and Chrome. This is the error from FF±
Uncaught exception: ReferenceError: Undefined variable: i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what
Error thrown at line 1, column 0 in javascript:comments (i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what,1);:
comments (i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what,1);
In this, i_heart_chaos_ihc_after_dark_independence_day_through_a_bullhornthis_is_what is the value of entry.url.
I'm just not getting why this error appears, as far as I know, everything should work.
I know that there are questions looking similar to mine, but I couldn't figure out the answer. If you want to see the whole source, it's here.
Surround entry.url with quotes:
$('#reactions' + i).attr('href', 'javascript:comments ("'+entry.url+'",'+i+');');
The best way to fix the issue is to do it the "jQuery way". Instead of adding a href attribute that executes JavaScript, add a click event:
$('#reactions' + i).click( function() {
comments( entry.url, i );
});
Similarly don't use document.write() but add elements to the document using jQuery functions.

javascript error for the textbox

<script type ="text/javascript" >
function toggletr()
{
debugger;
var Inputs =$get("TextBox1");
}
</script>
i trying this i am getting error:
Microsoft JScript runtime error: Object expected
but in textbox it contains value
//var Inputs = document .getElementById ("TextBox1");
if i do like this i am getting the value.
can any one tell me how to solve this one in javscript using $get() or JQuery
how to assign value
thank you
Also make sure the definition of the toggletr function appears earlier in the document than calls to it. Try it with the toggletr function defined in the <head> section of your page if it isn't already.

Categories

Resources