javascript

Most correct way to select option in <select> box

I know there are multiple ways to select a particular option from a using jQuery: $select.val("someValue") $option.attr("selected", "selected") $select[0].selectedIndex = 1 Assuming you have both the index of the option you wish to be selected and its value, what's the most correct way (from the above, or otherwise) to make it selec...

jQuery - Hide a div menu after clicking outside div

I've build a drop down menu at: http://www.ourbridalsongs.com/new_header/header.php When you click on the up/down arrow next to the logo - the menu appears - I'd like to make it disappear when clicking anywhere else on the screen - for some reason it's getting stuck and doesn't slide back up. Can anyone help resolve this! Here's my s...

Any way to improve this regular expression?

Hi guys - I'm kinda a newbie at regular expressions, so would appreciate a bit of peer feedback on this one. It will be heavily used on my site, so any weird edge cases can totally wreak havoc. The idea is to type in an amount of an ingredient in a recipe in whole units or fractions. Due to my autocomplete mechanism, just a number is ...

PhoneGap for mobile and Appcelerator for desktop+mobile?

It seems that PhoneGap is only for mobil devices while Appcelerator is for desktop and the mobile, am I correct? ...

Is it possible to tell whether or not some javascript code call particular function?

I am trying to build some sort of a javascript "antivirus" that would try to catch particular function calls. So lets say I've got some random javascript file, can I check if it doesn't use function jQuery.trim() (just for example sake) anywhere? It seems like pretty complicated task, plus there are eval and base encodings which could...

JavaScript: Saving certain data to a csv

I understand that JavaScript isn't really made to open and save files. The best method I've seen to get this to work is to use a form and then POST all the information I need to a PHP file that can than save the information I want to a file. I plan on producing this kind of data and storing it to a csv: Name,Low,High,Number Using inpu...

Check if an element exists in the DOM

The following snippet is not working for me. Basically I want to check if there is an input element with the name "documents[]" and the value item.id and return void. I thought this line would do it: $("input [name='documents[]'][value='"+item.id+"'") != false. However the statement returns true every time. I have looked at the docume...

How to show images or data in bottom to top in a table in php

I have more than 30 images and and i am getting them in a loop,Currently i am showing 7 images in a row but i want like this that after first 7 images which are shown in row the next seven will be shown in its above row and the next seven in it its above row in a table.i want to do it dynamically in php. ...

Change link color with javascript for style defined by scss

I have scss than looks something like #container{ a{ color:white; } } And I would like to change the links to another color using javascript. IE function changeColorTo(color){ //insert help here } Thanks. ...

Positioning an image in middle of the screen

Hi can someone please tell me how to position an image in the centre of the screen using javascript? Would I get the screen height and divide by 2? How would I get the screen height? Thanks! ...

Setting a cookie to prevent music from playing

OK, some I'm using jPlayer for some music on my site, and I have an opt out functionality that I would like to implement here, but I need a little help getting started. So, I've set a cookie: $.cookie('autoPlay', 'no', { expires: 365 * 10 }); So, I like to set up a conditional as follows: if(cookie == 0) { noMusic; } else { play...

How do I embedd a graph in asp.net

I'm looking to graph basic database data in a X Y axis graph. I would like a solution where the users do not need to download any extra plug-ins (i.e. Silverlight). Looking for the most efficient/fastest solution where the chart is embedded into the page as a graph, instead of just looking at the table data. Is there a built-...

The regular expression doesn't work

Trying to replace any non alpha-numeric characters with a hyphen. Can't see why it shouldn't be working. It returns the original string unchanged. item.mimetype = "image/png"; var mimetype = item.mimetype.toLowerCase().replace("/[^a-z0-9]/g",'-'); ...

browser displays the javascript code instead of html page in rails

Hi, I got a weird problem, here is the snippet of my code, View 1: <%= javascript_include_tag :defaults %> <% remote_form_for (@group, :group, :url => { :action => 'addgroup' }, :update => 'activitypage') do |form| %> <%= submit_tag "Add!", :class => "submit" %> <% end %> Method 'addgroup', def addgroup ##<some code her...

How to extract values using javascript ?

Hi , I have one string var str = ''; str += 'category='+jv('category')+'&'; str += 'refresh_rate='+jv('refreshRate')+'&'; str += 'submit=Y'; now I want to take values from jv('category') and jv('refreshRate') in separate string in javascript (I want to extract values after "=" and before "&"). Thanks. ...

How to quickly develop a sortable, paged data grid of a MySQL table in PHP?

How do I quickly develop a sortable, paged data grid of a MySQL table in PHP/JavaScript? If the grid could sort/page and download data via AJAX it would work better, of course :) I could develop it manually using AJAX to update the datagrid on sort/page navigation, but I was wondering if any datagrid components already existing that wo...

Accessing from the page in LowerFrame to the page in UpperFrame causes undefined error!

My website consists of two frames, let's say upperFrame and lowerFrame. On the document ready of the page in lowerFrame, it access one of textbox located on the page of upperFrame. Sometimes, since the upperFrame do NOT complete its loading, lowerFrame get the undefined while it access the upperFrame. Let me know if there are Any solut...

What JavaScript frameworks are out there for building smartphone websites?

Hi all, I'm looking to see what JavaScript Frameworks exist for the creation of Smartphone websites and what your experiences with them have been? Similar to the work in progress jQuery Mobile (http://jquerymobile.com/) Thanks, Denis ...

Stop page scrolling from focus

I just installed a script to focus at my first input field, which is toward the footer. The focus works great, but the page scrolls to the bottom after loading. Can I still use the focus and stop the page from scrolling down to the first input field? http://www.ubspack.com/ ...

Selected text event trigger in Javascript

It may sound a newbie question but I wanted to know how I can trigger a custom JavaScript function when someone selects a given text fragment on a page using mouse. Also is there any way to find the position of selected text on the webpage? Update: To be more clear, text fragment can be part of a sentence or a word or a phrase or whol...