javascript

How to store and optimize large values in cookies

I need to store the user preferences in a cookie. I have three multiple select drop downs & date. User is allowed to select all the values in dropdowns. If I store all the unique (8 characters) values in a cookie, then it will get overloaded. I need a mechanism to do some mapping so that minimal value is stored in cookie. My require...

Javascript Date: Ensure getMinutes(), getHours(), getSeconds() puts 0 in front if necessary

Hi all, Looking for a creative way to be sure values that come from the getHours, getMinutes, and getSeconds() method for the javascript Date object return "06" instead of 6 (for example). Are there any parameters that I don't know about? Obviously I could write a function that does it by checking the length and prepending a "0" if need...

Mapping keystrokes to actual value? - Javascript

Hi folks, any cool libraries that you know about around? =) ...

REGEX: Trying to create a reg. exp. that can find a string in the referrers host name

I am trying to create a JavaScript regular expression that can find a keyword in the referrers host name. It cannot be in the file path, just the host name. So... these should pass: http://keyword.com/ http://www.keyword.com/ http://keyword.example.com/ http://examplekeyword.com/ But these should not: http://example.com/keyword http:...

Constrain a YUI Container in a DIV

Is it possible to constrain a draggable YUI2 Container in a DIV instead of the whole page? I know its possible using YUI3 Drag n Drop: http://developer.yahoo.com/yui/3/examples/dd/constrained-drag_clean.html ...

How to make a controled "shuffle" order?

I have a set of quiz game questions in a sql database (javascript and sqlite actually). The questions all have a difficulty level from 1 to 5, 5 being hardest. Here is a simplified visualization of the data... +---------+--------------+ | id | difficulty | +---------+--------------+ | 1 | 1 | | 2 ...

Detecting autocomplete on form input with jQuery

I have a form that detects if all the text-fields are valid on each keyup() and focus(); if they're all valid, it will enable the submit button for the user to press. However, if the user fills in one of the text inputs with a browsers autocomplete feature, it prevents the submit button from being enabled. Is there a way to detect if an...

Safari 5.0 Extension Scripts Won't Run on Local Files

Hi, I wrote a very simple extension for Safari 5 that only outputs a single log message from a start script. This is the start script: console.log('start script running'); If I go to any internet page (eg. http://www.yahoo.com) the log message appears in the error console. But if I open any local html page no log message appears. By l...

Auto-resize iframe based on content height

I have a site on my server that is pulling in an iframe from an external site in which I do not have access. I want the iframe to resize the height based on the content that is being pulled in so the page as a whole looks like a single page. *I do not need to know how to get rid of the scroll bars. Does anyone have any ideas? Thanks ...

A (somewhat obscure) Javascript inheritance question

I have been experimenting with a design pattern in Javascript that would allow me to have what appears to be singleton functions that can be overridden by instance functions. Here's a brief example: Date.tomorrow = function () { return Date.today().add(1).days(); } (function(p) { p.tomorrow = function() { var date = this.clon...

why cant I do this in js

I want to do this <?php $dropDown = "<select><option value=\"0\">1-50</option><option value=\"50\">51-100</option><option value=\"100\">151-200</option></select>"; ?> <html> <head> </head> <body bgcolor="333333"> <script language="javascript"> <!-- var params = new Object(); params.dropDown = <?php print $dropDown; ?>; </scri...

Random image url when reload

Hi, What I want is that the URL to some specific images should change on reload / new visit. No news but this is how it looks today... <li><a href="http://nameToSite/images/bkg1.jpg"&gt;&lt;/a&gt;&lt;/li&gt; Is it possible to make a jQuery url change To something like <li><a href="http://nameToSite/images/randomImages[1].jpg"&g...

set select option back to default selected

I'm trying to set the select option back to the "choices" every time I finish adding a new row. How can I do it here? Please help. Btw, adding new row(s) works just fine. Here is what I've got so far: $(document).ready(function() { $('#Add-btn').live('click',function() { $("#tabName tr:last").before("<tr><td class='greyed'><inp...

How to remove mouseover/mouseout event

I have a site with three tabs that I'm trying to dynamically add mouseover/mouseout event depending on which tab is clicked, the problem is that it appears that the mouseover/out events are 'bound' to the tab after they're called. Is there a way to 'unbind' the event from the tabs? Here's what my js looks like onTab1Clicked() { $(...

Saving the DOM as HTML after modification

In an Rails app I want to modify the DOM of a web page using javascript Can I save the resulting HTML (of the whole page) after each modification to a database? Thanks. ...

jQuery trigger event when click outside the element

$(document).click(function(evt) { var target = evt.currentTarget; var inside = $(".menuWraper"); if (target != inside) { alert("bleep"); } }); I am trying to figure out how to make it so that if a user clicks outside of a certain div (menuWraper), it triggers an event.. I realized I can just make every click fi...

Can I make a <button> not submit a form?

I've got a form, with 2 buttons <a href="index.html"><button>Cancel changes</button></a> <button type="submit">Submit</button> I use jQuery UI's button on them too, simply like this $('button').button(); However, the first button also submits the form. I would of thought that if it didn't have the type="submit", it wouldn't. Obvi...

what's the first event fired when a Web page is loaded to the browser

As asked in the title, what's the first event fired when a Web page is loaded to the browser? I believe there are events before window.onload. What are they, and which one is the first fired? ...

javascript cancelBubble does't work on firefox

Hi all , the blow code work fine on IE,but does't work on firefox,why? It's some problem on my code? How to fix it? thanks! <html> <head> <style> body{font-family:Arial;font-size:12px;font-weight:normal;line-height:28px;} .product_tips{ width:500px; background:#f0f0f0; border:1px solid #ccc; padding:8px; margin-top:3px; } span{cursor:po...

JavaScript Object.prototype by value

I want to do something like Object.prototype.dataTransfer = new DataTransfer();, but I want every new object to have it's own dataTransfer. How do I do this? For example, if I do var a = new Object(); var b = new Object(); Object.prototype.dataTransfer = new Object(); a.dataTransfer.prop = 1; b.dataTransfer.prop = 2; I want a.dataT...