javascript

Best practices for passing data from asp.net-mvc to javascript

I've been working with ASP.NET MVC and Javascript/jQuery a lot lately and I seem to be heading in a direction where I'm always needing to pass some dynamic value "to" my javascript. When the script is right in the page, I've done something like this: var isEditable = <%=ViewData["editable"]%> I like how this is quick & easy and just l...

jquery detecting when we are at the end of text in textarea

Hi all, I am just trying to learn jquery, and I was wondering how can you figure out when, given a bunch of text in a textarea, is the user at the end of textarea and tries to click down. For example, the last line of the text is asdf, and when the user is at that line, and presses down on the arrow key, i would like to get an event of...

Help with Javascript to JScript Conversion

Background: I have data that I'm encrypting with javascript on the client side that needs to be decrypted on the server side. As far as I can tell, the javascript AES library I'm using does not interop with the C# Rijndael library. Thus, I'm left to essentially implement the javascript AES in C# for use. I'm going to try to compile ...

How can I get the element the caret is in with Javascript, when using contentEditable?

Hi, Let's say I have some HTML code like this: <body contentEditable="true"> <h1>Some heading text here</h1> <p>Some text here</p> </body> Now the caret (the blinking cursor) is blinking inside the H1 element, let's say in the word "heading". How can I get the name of the element the caret is in with JavaScript? Here I would li...

Why is this JSON not being parsed correctly?

My problem is that this JSON is not being parsed by JavaScript or the jQuery API. I am including the code below and a URL where the JSON output is. This JSON is being parsed in JavaScript as nothing: //something like this: alert(data); // gives an object alert(data.horas[0].hora; // gives undefined The JSON itself: {"horas": [{"hora...

How to get a google map to use 100% of its parent container?

I have tried to do this in many different ways but the most obvious was this: var map2 = new GMap2(document.getElementById("map2"), {size:"100%"}); That does not work. ...

How do I DRY up my CouchDB views?

What can I do to share code among views in CouchDB? Example 1 -- utility methods Jesse Hallett has some good utility methods, including function dot(attr) { return function(obj) { return obj[attr]; } } Array.prototype.map = function(func) { var i, r = [], for (i = 0; i < this.length; i += 1) { r[i] = func(this[i]); ...

jQuery cloneTo instead of appendTo?

Hi. I am trying to use jquery appendTo in order to copy an element into another container. The object is indeed appended but, it is removed from the source. Is there a way I can append the element while leaving the source element where it is? call it copy call it clone call it whatever you feel like. Here is my current code: jQuery(do...

Can scripts be inserted with innerHTML?

I tried to load some scripts into a page using innerHTML with a div. It appears that the script loads into the dom, but it is never executed (at least in ff and chrome). Is there a way to have scripts execute when inserting them with innerHTML? sample code <!DOCTYPE html> <html><head> <title>test</title> </head> <body onload="document....

Cross-site AJAX using jQuery

Hello, I have an existing jQuery plugin which makes a lot of AJAX calls (mostly JSON). I am wondering what is the quickest to allow it to do cross-site calls i.e. the $.get and $.post URL's will not be from the same domain. I have heard of JSONP, but was wondering if someone could give me an concrete example to go about the whole proce...

How does 'this' work in JavaScript?

I know there are several other posts on this topic but they still leave me confused. I've included jQuery and everything and, I have a simple javascript class like this example: function CarConstructor(){ this.speed=19; // in mph this.make="Ford"; this.fillKph=fillKph; } function fillKph(){ $("#kphdiv").html(this.speed*1.61); ...

Why does Toggled value return always OFF.

I would like to get value ON or OFF by toggled. And default value and view is OFF. But that code return always OFF. <div id='toggl1'> <fieldset> <form id='search' method='post'> <input id='search_withbydate' name='search_withbydate' type='hidden' value='OFF'> <div class='row'> ...

What lightweight JS tab with good design are you using?

Hi Guys, Right now I am usingjQuery UI Tab but it has a conflict in Drupal's fieldset accordion so I am thinking of using a lightweight javascript tab with a good design like rounded corners that is a javascript framework independent. What javascript tabs are you using? Or do you know any javascript tabs that is working in drupal and d...

Problem with DOM in IE

I wonder if IE doesn't support DOM method when creating a table in a containing element-div. Because I could not see the table when the JavaScript rendered. Please see the following: In the HTML: <div id="pageHeader"> <div id="filters"> ----- </div> </div> In the JavaScript: I created a div named "classifications". Th...

How to add 30 minutes to a javascript Date object?

I'd like to get a Date object which is 30 minutes later to another Date object. How to achieve it? Basically: Tue Jul 28 16:00:00 UTC+0800 2009 add 30 min to Tue Jul 28 16:30:00 UTC+0800 2009 Tue Jul 28 16:40:00 UTC+0800 2009 add 30 min to Tue Jul 28 17:10:00 UTC+0800 2009 ...

writing a function which creates a string (javascript) and then add it to a button as its attribute?

hi I have a Button in my .aspx web form and use c# 3.0 I want to add a javascript function to its attribute as its "onclick" event handler. the function has 1 parameter in order to check whether onclick javascript should get a confirmation from user or not. The parameter Datatype is bool But when I send true, execution of the program ha...

Quiting the page before a form submission

In my application I am showing the warning message when the user want to leave the page before submitting the form. I am using window.onbeforeunload() in the script. My application has a Master page. I have four different views for a single form. I am inserting record in first view itself. When user quits the page I want to make some D...

Good Javascript plugin to display tooltip briefly on page load

Hi, I need a plugin which highlights/points to a div box on the page on page load. The tooltip should then be able to be closed and/or will disappear after a few seconds. I am having difficulty finding one, as all the current ones seem to require the mouse to hover over the intended target. Are there any plugins that people recommend o...

How can I determine in JS if a function/method exists in IE7?

I wrote a quick and dirty logger as a jQuery plugin (function($){ $.log = function(debug) { if (console.debug) { console.debug(debug); }; }; })(jQuery); It works fine in Firefox, but in IE7, I'm getting the error console.debug is null or not an object How do I perform a function exists in Jav...

how to check the age of registrant during registration using jquery

I want to filter all the user who can register in my website. how can i filter the age of the registrant using jquery allowing 18 years old and above, but when the age is 13 to 17 years old they can register but they must check checkbox for parental consent. I am using a textbox with mm/dd/yyyy format. ...