javascript

Passing date to Date object results in an undefined variable in IE8

I've been stuck on this for quite a while and would appreciate some help if possible. Basically I receive a date from an API in the format yyyy-mm-dd. Amongst other things, I wish to display the weekday. Here is the relevant code: // jsonDate is in the format yyyy-mm-dd var splitDate = jsonDate.split("-"); var joinedDate = splitDate....

Doing AJAX with JSF 2.0 without using action listeners

I'm new to JSF. I am using JSF 2.0. I'd like to be able to use scripts that use ajax in a classical way, not going through JSF's f:ajax tag. However, I know that it's easy to mess up with the application's state if you go around JSF features too much. Has anyone done this before? Any ideas on how it should be done? Suggestions and exi...

Loading JS configuration from server?

I want my JS to load certain information that needs to come from the server. Examples would be URLs, language specific messages, etc. What is the best way to get this information from the server to the JS? Right now, I have such values stored in an actual JS file. I don't like this approach because information is duplicated on the serve...

A very basic JavaScript question about the document.write function

I'm new to JavaScript as well as jQuery. This is the only code I have on an otherwise blank page: <script type="text/javascript" src="jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function() { document.write('Hello World'); }); </script> When I load the page in a brow...

Cannot access javascript injected function

I am injecting the following code directly into my browsers address bar. If I edit it just a bit (whilst not even changing any code) from the HTML tab in Firebug, it will work. This piece of code will change the onsubmit event of all forms on a page to call a function which retrieves the field values of that form and sends it as a GET me...

How to add onload event in div?

<div onload="oQuickReply.swap();" ></div> Can i use for this? ...

Dealing with Responses to Ajax Requests

I am working on a project where I have to send an ajax request to some java based middleware that someone else is in charge of. 4 things can happen in response to the data I POST back... the userid is correct so the response I receive includes: XMLHttpRequest.responseText = "someurl.html" XMLHttpRequest.status = 200 the userid is corr...

Verlet integration bouncing

I am trying to learn Verlet integration, mainly because I'm bored, and want to spice up my normal "bouncing ball" learning exercise. I have a simple bouncing ball Canvas/HTML5 page at http://sandbox.electricgrey.com:8080/physics/. If you click on it you'll notice that the ball doesn't always bounce back to the same height. Sometimes it ...

How to access css properties in javascript when applied via external CSS file?

Hi, I have a little problem. When I set the css rule using some property, say, background-image in an external .css file and then try to access it using javascript in another external .js file, it does not work. That is to say I do not get any value for document.getElementById(someId).style.backgroundImage. But when I set the css rule ...

Restrict characters entered into a text_field

I have a text field where users enter a URL string, which cannot contain spaces or non-alphanumeric characters (if that's an accurate way of putting it). Is there a way in Rails to restrict entry into the text_field itself so that spaces and characters like /":}{#$^@ can be avoided? Thanks a lot. To clarify, the only characters that...

Is Chrome's JavaScript console lazy about evaluating arrays?

I'll start with the code: var s = ["hi"]; console.log(s); s[0] = "bye"; console.log(s); Simple, right? In response to this, Firebug says: ["hi"] ["bye"] Wonderful, but Chrome's JavaScript console (7.0.517.41 beta) says: ["bye"] ["bye"] Have I done something wrong, or is Chrome's JavaScript console being exceptionally lazy about...

javascript convert int to float

i have variable var fval = 4; now i want out put as 4.00 ...

Javascript Switch statement not working as expected with string

I'm trying to use the following switch statement in an ajax success callback: success: function(datain) { switch (datain) { case "ERROR. No ID. Try again": $(".errors").append('There was an error.'); break; ...

javascript questions

Today I am going to attend a seminar on basic java script. Can anyone give me some good question /answers which I can ask in query session ? Seminar will cover : intro to java script,History ,Validation, browser compatibility, events,DOM. ...

need to strip out unwanted text

I need to strip out all text before and including "(" and all text after and including ")" in this variable. var this_href = $(this).attr('href'); The above code produces this... javascript:change_option('SELECT___100E___7',21); However it can produce any text of any length within the parenthesis. A Regex solution is OK. So in t...

javascript to check if element visible and set "setInterval" accordingly

Hi, LE2. Any other ideas on how to fix this? I have this code and can't figure why is not working properly: $(function autorun() { if ($("#contactForm").is(":visible")){ setInterval( "refreshAjax();", 150000000000 ); } else { setInterval( "refreshAjax();", 15000 ); } setTimeout("autorun();", 2000) }); ... <body onLoad="autorun(...

extract line from javascript

Hi I need to extract this line of code from a script i am retrieving via ajax.. this line new Date(2010, 10 - 1, 31, 23, 59, 59) from jQuery(function () { jQuery('#dealCountdown').countdown({ until: new Date(2010, 10 - 1, 31, 23, 59, 59), serverSync: serverTime, timezone: +11, compact: true, format: 'HMS', expiryUrl: BASE, la...

Jquery: Select the element that called the function

I'm calling a function in the element itself via an onclick attribute because I need php to dynamically give a value in one of the functions parameters. When I try to reference the calling element in the function via "$(this)", it ends up referencing the entire window and not the element. How do I fix this? ...

Zend Json encoding and using in javascript

Hello. I am using Zend Framework. My task is to send JSON data from controller to Javascript. I have an simple array: $array = array('a' => 1, 'b' => 2); After i am encoding this array to json format: $jsonData = Zend_Json::encode($array); But I don't know, how I can get this data in Javascript. I send an ajax request with jQuery....

javascript quotes inside quotes, string literal issue

I am trying to display text in a javascript tooltip I keep getting unterminated string literals even though: a) the quotes are being slashed, b) there are no line breaks The text I am trying to display is: "No, we can't. This is going to be terrible." (its a quotation from an individual and I want those quotes to display in the tool...