javascript

How to rewrite this javascript that receives a request object as JQuery

Hi everyone, I want to learn how to do some AJAX (using comets) with JQuery, I have a Javascript version, am curious to see if anyone knows the JQuery equivalent. function go(){ var url = '<%= ApplicationPathUtils.getApplicationPath(pageContext) + "/Weather" %>'; var request = new XMLHttpRequest(); request.open("GET", u...

Looping through all instances of a javascript object

Hi, if I have an object constructor like: function cat(color, sex){ this.color = color; this.sex = sex; } and I make some cats: var fluffball = new cat("blue","male"); var shiznitz = new cat("red","male"); var slothersburger = new cat("green","female"); Is it possible to loop through all the cats I have declared? Somethin...

Browser "Busy State" with Ajax

Hi All, We've got an ajax request that takes approx. 30 seconds and then sends the user to a different page. During that time, we of course show an ajaxy spinner indicator, but the browser can also "appear" stuck because the browser client isn't actually working or showing it's own loading message. Is there an easy way to tell all maj...

Jquery: How do I trigger a modal window just from the existence of an element

I have a form that generates the following markup if there is one or more errors on submit: <ul class="memError"> <li>Error 1.</li> <li>Error 2.</li> </ul> I want to set this element as a modal window that appears after submit, to be closed with a click. I have jquery, but I can't find the right event to trigger the modal window. He...

simple question about difference between array.item(n) and array[n] ?

Hello everybody. I have a question. I was recently writing some javascript code in dreamweaver and in it's code complete everytime i would deal with array of elements it will give me array.item(n) rather then array[n] What is the difference between those two ? Some example code: function hideAllSubMenu(){ var submenu = document....

Get the browser viewport dimensions with Javascript

I want to provide my visitors the ability to see images in high quality, is there any way I can detect the window size (or better yet, the viewport size - see green area) of the browser with Javascript? ...

how does facebook do this onkeyup and onchange at the password change?

I noticed that in the facebook the change passwords, they have this nice alert at the bottom telling you that the passwords do not match or if the confirm password is too short. However when i use the firebug, i do not see any onkeyup or onchange. And they did it very well regardless whether i type or if i copy a string and paste, it w...

Detect key event (Enter) with JQuery in Javascript (on Linux platform)

Hi there, Update: =========================================== I finally figured out that "keypress" has a better compatibility than "keydown" or "keyup" on Linux platform. I just changed "keyup"/"keydown" to "keypress", so all went well. I don't know what the reason is but it is solution for me. Thanks all who had responsed my questi...

Javascript Regex: Bolding needles in a haystack (edited question)

This is a slightly modified version of the question here. The difference is I don't the special characters to be included in the bold tags if they are on front or back. Given a needle and a haystack... I want to put bold tags around the needle. So what regex expression would I use with replace()? I want SPACE to be the delimeter and I ...

What is the difference between these two code samples?

Code 1: var Something = { name: "Name", sayHi: function(){ alert(Something.name); } } Code 2: function Something(){ this.name = "Name"; } Something.prototype.sayHi = function(){ alert(Something.name); } Edit: So, Guys, you mean the Second one is better? or more "formal" ? ...

ASP.NET MVC/jQuery: Inplace Editing

Hello, I want to do inplace editing where I have regular text (coming from a Model) with an edit button next to it. When the edit button is clicked, I want a editable textbox to appear where the regular text was, and then commit a change via AJAX. I already solved how to commit, but I don't know how to place the editing control accurate...

Inverting binary networks

How can I invert a binary equation, such that I can find which inputs will produce a given output. Example: Inputs: i0 through i8 Outputs: o0 through o8 Operators: ^ = XOR, & = AND Binary equations: (1&i0) ^ (1&i1) ^ (0&i2) ^ (1&i3) ^ (0&i4) ^ (0&i5) ^ (0&i6) ^ (0&i7) ^ (0&i8) = o0 (0&i0) ^ (1&i1) ^ (0&i2) ^ (1&i3) ^ (1&i4) ^ (0&i5)...

Question about some wild javascript syntax and contraints

Hey all, So I know javascript pretty well, but I'm not sure about this one. Tough to explain so I'll just show it: var view = new View(); view.rating = 4.5; Is there anyway to have view.rating be called as a function to manipulate the DOM a bit and set that rating to five? So in View: View.prototype = { rating : function() { ...

JavaScript object size

I want to know the size occupied by a JavaScript object. Take the following function - function Marks() { this.maxMarks = 100; } function Student() { this.firstName = "firstName"; this.lastName = "lastName"; this.marks = new Marks(); } Now.. i instantiate the student var stud = new Student(); so that I can do stuff like ...

Multi form submit in the page with ajaxform()

how to get the parent div id of current submit form with the ajaxform plugin I am not having any problems with the success state Thank you. below is my code. <script type="text/javascript" charset="utf-8"> $('.formsubmit').ajaxForm( { beforeSubmit: function() { // here want form parent div display loading.. var id = $(this).pa...

Jquery ajax onSuccess event

I am doing AJAX with JQuery but every time the "onSuccess" event must be executed after another AJAX request disconnected. Here is the code: d.ajax({ url: f.options.url.offline, dataType: "jsonp", jsonp: "callback", cache: false, data: { status: "offline", ticket: f.co...

What's the equivalent of IE's document.all in DOM?

I basically want to dynamically apply some style to all elements in a page, I know document.all is proprietary to IE, so, what's the equvalent (if any) in DOM? Is there an equivalent to * in css in DOM? Note: Don't want to use JQuery or any other JS lib for this, just JS, thanks ...

Greasemonkey-like Firefox plugin for automatic browsing

Is there a plug-in for Firefox that would allow user's Javascript code like Greasemonkey and be able to browse from page to page? I'd like to write a script to: Log in to a website. Follow several links. Make a GET request to that host periodically with given data and time intervals. Make a POST request based on the results of the pre...

JavaScript replace form submit

I developed an application that is fully based on SJAX (synchronous jax). I am sending data thru POST-SJAX instead of form submit. My idea is not to refresh the browser. The advantage of this method is: Number of HTTP request is reduced. Number of DB calls will be reduced. No need to repopulate data when the page refreshes. All I wa...

Converting sanitised html back to displayable html

I'm getting html data from a database which has been sanitised. Basically what I'm getting is something like this: &lt;div class="someclass"&gt;&lt;blockquote&gt; &lt;p&gt;something here.&lt;/p&gt; &lt;/blockquote&gt; And so on. So if I try to display it, it is displaying as <div class="someclass"><blockquote> <p>something here</...