javascript

How to neutralize injected remote Ajax content?

I'll be inserting content from remote sources into a web app. The sources should be limited/trusted, but there are still a couple of problems: The remote sources could 1) be hacked and inject bad things 2) overwrite objects in my global names space 3) I might eventually open it up for users to enter their own remote source. (It w...

javascript - document.form.textbox.style....can't seem to find this?

Can anyone help point me in the right direction - I have the following in a function: document.form1.textbox1.style.display = 'none'; which works fine. But I'm trying to find a list of all the possible 'elements'(?) that could come after style, e.g. '.display=', '.length=' etc, but I don't know the proper name/terms so the searches i...

How random is JavaScript's Math.random?

For 6 years I've had a random number generator page on my website. For a long time, it was the first or second result on Google for "random number generator" and has been used to decide dozens, if not hundreds of contests and drawings on discussion forums and blogs (I know because I see the referrers in my web logs and usually go take a ...

Date parsing with regular expressions in JavaScript

I'm using match() in JavaScript to parse a dates from an RSS feed, I just can't get my head around the correct regular expression to find the date format. Here's the date: 2009-05-11 16:59:20 And the regular expression so far: if (dateToParse.match(/^\d\d\d\d-\d\d-\d\d/)) { dateTimeSeparator = " "; monthIndex = 0; ...

sort not working with integers?

Trying to get the highest and lowest value from a array that I know will contain only integers seems to be harder than I thought? var numArray = [140000, 104, 99]; numArray = numArray.sort(); alert(numArray[0] + ", " + numArray[numArray.length - 1]); I'd expect this to show "99, 140000". Instead it shows "104, 99". So it seems the sor...

Javascript if typeof ='undefined' in try/catch space

I have code that is wrapped in try/catch block. I use typeof to find out if a variable is defined: if (typeof (var) == 'string') { //the string is defined } However, using this in a try/catch block, jumps to the catch part instead of doing what it is suppoed to do (do something with the string if its defined). How can I check i...

jQuery html() acting really slow

I was testing something I read earlier about how random Math.random() really is, and wanted to display 10000 numbers that was supposed to be a random number between 0 and 10000000. To see the test, I chose to just join the array of random numbers to a string with <br> between each integer. And then I just did $("#"+elm).html(randomNumbe...

XPath or querySelector?

XPath can do everything querySelector can do, and more, so when would you ever choose the latter? I haven't seen any speed benchmarks comparing the two, so right now I'm choosing based on syntax conciseness, which seems kind of arbitrary. Edit: I probably should have stated that I'm writing Greasemonkey scripts for Firefox, so I'm not w...

calling php from js (w/ ajax)

Hi, I'm building a basic forum where every post contains some text, first and last name, and the date the message was written. I'd like to have the board update with AJAX constantly, and to add new messages on the fly as they are written. I have a file, getlatest.php?date=... that retrieves all messages from the date in the $_GET till N...

Can I rewrite a Javascript function using Excel VBA?

Hi, Don't know how to do this at all, but if the onclick of a button is similar to below: onclick="ConfirmAvailable();" function ConfirmAvailable() { if (document.getElementById("AvailableCB").checked) { return YesNoDialog("'Are you sure?'"); } else { return true; } } Is it possible, if I set ConfirmAvailable()="" using Exce...

Listener for property value changes in a javascript object

Going through javascript documentation, I found the following two functions on a javascript object looks interesting: Watch - Watches for a property to be assigned a value and runs a function when that occurs. Unwatch - Removes a watchpoint set with the watch method. Sample usage: o = {p:1}; <br/> o.watch("p",<br/> function (id,old...

What makes javascript dangerous? What uses that javascript can be used as?

I have been dabbling around with javascript for fun. I keep wondering why there are some people that do not like javascript because it can be easily abused or badly written. Then there are some people that love javascript because it is a powerful language and very useful for various purposes. ...

Get code outside quotes with regexp in javascript

Is there a way to get a piece of code that is not between quotes (single or double) in javascript with regular expressions? if i have this string: 'this is a test "this shouldn't be taken"' the result should be: 'this is a test' ...

HiddenField EventHandler ValueChanged not fired when changed via Javascript

I have a HiddenField control that is created within my ASP.NET server control. I added a new EventHandler for the ValueChanged event. Will this event be fired when the value of my HiddenField changes from within a javascript function? The main problem I am having is trying to retrieve the value of my HiddenField server-side when the v...

Inserting a text where cursor is using Javascript/jquery

I have a page with a lot of textboxes. When someone clicks a link, i want a word or two to be inserted where the cursor is, or appended to the textbox which has the focus. For example, if the cursor/focus is on a textbox saying 'apple' and he clicks a link saying '[email]', then i want the textbox to say, 'apple [email protected]'. How ...

Is there any good reason for javascript to be inline

I've been building a site. At some stage I noticed that IE display was a little broken and Chrome had all but rendered nothing but the body tag (empty), and FF all looked good. After throwing my keyboard around the room and bashing my head against my mouse, I discovered the problem. I had left (don't ask how or why, must have been som...

How can I tell if "abort()" has been called on an XMLHTTPRequest

Simple question, but not obvious from the Mozilla JS docs. Anyone know the answer off the top of their head? ...

What context is the jQuery.post callback function invoked in?

Lets say for example: $(".button").click(function() { $.post("commandrunner.php", { param1: 'value', param2: 'value2', param3: 'value3' }, function(data, textStatus) { $(this).parent().after('<p>button clicked</p>'); }, "json" ); }); I ra...

JQuery, event bubbling on table cells. How to work out which row is clicked on

I have table enclosed by a div that looks similar to this....... <div id="records"> 10 | text1 | Delete 23 | test2 | Delete 24 | text3 | Delete 32 | text4 | Delete </div> I'd like to make the "Delete"s clickable which calls an ajax script to remove them from the database. Each of the 'Delete's has a class of "delete_record" The ta...

How to set callback on single items using jQuery

I have a js function which has, until now, always been the callback for a click event, and therefore relies heavily on the 'this' pseudo-variable. 'this' is a <li> element. However I now have a circumstance where it is sometimes triggered using more convoluted route, and in these circumstances 'this' is an entirely different element. Ho...