javascript

javascript innerHTML without childNodes?

hi all im having a firefox issue where i dont see the wood for the trees using ajax i get html source from a php script this html code contains a tag and within the tbody some more tr/td's now i want to append this tbody plaincode to an existing table. but there is one more condition: the table is part of a form and thus contains che...

Getting text of html select in javascript?

select.onchange = function() { this.value; } It's easy to retrieve the value but now I need the text of the selected element. How to do it? ...

How to simply encode and decode a string variable with javascript.

I need to simply encode a string variable (my api key) so that is not easily readable by human eyes, I need it to easily decode back to exactly the same initial string. What is the standard practical and fast (less computing on the user side) way to do this? Many thanks in advance! ...

jQuery UI sortable: determining in what order the items are

Here is an interesting use of JavaScript: reordering items with drag and drop. The implementation itself in my page works fine, but is there a way to determine in which order the user put the items? I'm asking because I want to load and save the item order in a cookie. ...

Cannot output json from MySQL - getting null value

I'm using following code but cannot return data from MySQL. This is the output: <script type="text/javascript"> var somethings= [null,null,null]; </script> It does have three post, but I couldn't get the title(message) output. EDIT: this is the code I'm using: <?php $session = mysql_connect('localhost','name','pass'); ...

How do I DRY up business logic between sever-side Ruby and client-side Javascript?

I have a Widget model with inheritance (I'm using Single-Table Inheritance, but it's equally valid for Class-per-Table). Some of the subclasses require a particular field; others do not. class Widget < ActiveRecord ALL_WIDGET_TYPES = [FooWidget, BarWidget, BazWidget] end class FooWidget < Widget validates_presence_of :color end cl...

JavaScript: Achieving precise animation end values?

I'm currently trying to write my own JavaScript library. I'm in the middle of writing an animation callback, but I'm having trouble getting precise end values, especially when animation duration times are smaller. Right now, I'm only targeting positional animation (left, top, right, bottom). When my animations complete, they end up hav...

AJAX callback in Obj constructor

I have a class object called Location that works with Google in order to geocode a given address. The geocode request is made trough an AJAX call and handled via a callback that will initiate the class members once the response arrives. Here is the code: function Location(address) { this.geo = new GClientGeocoder(); this.addres...

Getting Null value with JSON from MySQL, how to retrive data from MySQL to JSON correctly?

I'm using following code but cannot return data from MySQL. This is the output: <script type="text/javascript"> var somethings= [null,null,null]; </script> It does have three post, but I couldn't get the title(message) output. EDIT: this is the code I'm using: <?php $session = mysql_connect('localhost','name','pass'); ...

JQuery ajax request returns error and status 0

I use this pseudo-class to make ajax request to server: function RequestManager(url, params, success, error){ //save this ajax configuration this._ajaxCall = null; this._url= url; this._type = params.type; this._success = function(){ alert("ok"); }; this._error = function(){ alert("ko"); }; } RequestManager.prot...

Resizing to page width for print style sheet

So I've got a page that shows an image with some absolutely positioned text on top of it. I want to write a print style sheet for it so that: the image is resized to fit the width of the page the text is repositioned and resized to maintain relative position and size with the image behind it So I know I can do (1) with just max-widt...

Javascript Print Script Not Working in IE

Greets! I'm a noob struggling to learn html and javascript - getting there slowly. I'm trying to print a DIV served up by SimpleModal. The page is at: www.planetsarsfield.com This "Print" function is in the recipe box at the bottom. Everything works great in FF, but it doesn't work at all in IE8. I must be doing something fundament...

Mootools 1.2 ToolTip - doesn't read input fields

I'm using MooTools Tooltip by Constantin Boiangiu as a form popup. It displays fine but when I try to read the values to do a ajax call using Request, it sends blank. After debugging using Firefox I noticed that any control inside the Tooltip popup shows the values which were in html. Any user input isn't reflected when they are read u...

What is a reverse reference to the DOM object?

In this link: http://css-tricks.com/snippets/jquery/jquery-plugin-template/ it has a line of code that says // Add a reverse reference to the DOM object base.$el.data("yourPluginName", base); what does the "reverse reference to the DOM object" mean? ...

Why does Google append while(1); in front of their JSON responses?

This is something I've always been curious about, is exactly why Google appends while(1); in front of their (private) JSON responses. For example, here's a response while turning a calendar on and off in Google Calendar: while(1);[['u',[['smsSentFlag','false'],['hideInvitations','false'],['remindOnRespondedEventsOnly','true'],['hideInv...

How do templating engines in JavaScript work?

Hello, Could you please explain me, how do templating engines in JavaScript work? Thank you. JSON { "color" : "red"} Template <strong><%=color%></strong> Result <strong>Red</strong> ...

Rhino and Javascript 1.8?

Is it possible to have Rhino use a newer implementation of JS than 1.7? Do we have to wait for mozilla to do this, or is there a community project that has taken the lead? Thanks. ...

Regular expression test can't decide between true and false (JavaScript)

I get this behavior in both Chrome (Developer Tools) and Firefox (Firebug). Note the regex test returns alternating true/false values: > var re = /.*?\bbl.*\bgr.*/gi; undefined > re /.*?\\bbl.*\\bgr.*/gi > re.test("Blue-Green"); true > re.test("Blue-Green"); false > re.test("Blue-Green"); true > re.test("Blue-Green"); false However, t...

JavaScript + HTML textbox problem!

i'm trying to get the value of 2 textboxes with Javascript. textbox 1, nothing wrong. textbox 2, same code, there happends nothing!!!!!! here is the code var fieldname; fieldname = document.getElementById("div"+field).getAttribute("field"); alert(fieldname); // RETURNS "Birthdate" var textval; textval = documen...

How to remove invalid UTF-8 characters from a JavaScript string?

I'd like to remove all invalid UTF-8 characters from a string in JavaScript. I've tried using the approach described here (link removed) and came up with the JavaScript: strTest = strTest.replace(/([\x00-\x7F]|[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3})|./g, "$1"); It seems that the UTF-8 validation...