javascript

How to avoid the form being submitted after displaying alert?

If the user name and password does not match it displays a alert but if i click ok to the alert the form is logged in.Can any one tell me how to avoid it?Thanks. <html> <f:view> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <h:form id="loginForm"> <h1><cen...

When using firebug, do I have to remove the console outputs when deploying?

Hi, I am using firebug for debugging etc. When I deploy, it seems as though I have to remove all the console.log statements from my javascript code? When viewing on a browser that doesn't have firebug I am getting errors relating to console... ...

Javascript Regex object and the dollar symbol

In the code below. I expected true but i am getting false instead. What am I missing? var text = "Sentence $confirmationlink$ fooo"; alert(placeHolderExists(text,'confirmationlink'); // alerts false function placeHolderExists(text,placeholdername) { var pattern = new RegExp('\$'+placeholdername+'\$'); return pattern.te...

Javascript search and replace

I would like do do the following in Javascript (pseudo code): myString.replace(/mypattern/g, f(currentMatch)); that is, replace string isn't fixed, but function of current match. ...

Set cursor position in html textbox

Does anybody know how to move the cursor in a textbox to a particular position? For example if a textbox (e.g. input element, not textarea) has 50 characters in it and I want to position the cursor before character 20, how woould i go about it? Jon ...

Create programmatic colour picker

How would one create a deterministic Javascript HTML colour picker which given arguments of how many colours are desired returns an array of HTML hex colour codes, ie: function createColours(numColours) { return [/* colours array of size numColours */] } The colours themselves can be chosen / generated randomly, but the method m...

The "this" in javascript and ASP.NET control prefixes

I have code that renders the following HTML <tr> <td>Control 1 with onclick="javascript:Test(this);" </td> <td>Control 2</td> <td><span><div>Control 3</div></span></td> </tr> function Test(myThis) { //Here I would like to get references to the siblings of Control 1 (in this ex: Control 2, Control 3) //and disable them. Any id...

Adding a new item to a combobox with yui

Can anybody help me, please ? (sorry for my english, I'm french) I've a combobox and i want insert an item "add-item" before read an array of data that populate my combobox. To sum-up : 1- Adding to my combobox "add-item" (add before read the array), 2- Adding to my combobox data from my array (it's ok for this part). Here my code : ...

Displaying a spinner for a webservice call (Like UpdateProgress Control)

Right now I have a page where unfortunately there is a mix of update panels and calls to webservice web/script methods from javascript. I have an update progress control which shows a spinner for update panel activity. But when I do webservice calls it isn't displayed. How would you recommend I solve this usability issue since the use...

How to get a GreaseMonkey script to listen for elements with a specific class being inserted into a page

I'd like my GreaseMonkey script to run a function whenever elements with a specific class are inserted into a page. What's the most idiomatic way of doing that? If it helps, it's a <select> element that is being inserted. ...

Do the keys of javascript associative arrays need to be strings, or can they be any object?

that's it, that's my question. thanks! -Morgan ...

New to JSON, what can I do with this json response

Hi, A website returns the following JSON response, how would I consume it (in javascript)? [{"ID1":9996,"ID2":22}] Is JSON simply returning an array? ...

Force <div></div> to the bottom of the web page centered.

Hi, I have a <div>...</div> section in my HTML that is basically like a toolbar. Is there a way I could force that section to the bottom of the web page (the document, not the viewport) and center it? ...

Setting nodeValue of text node in Javascript when string contains html entities

When I set a value of a text node with node.nodeValue="string with &#xxxx; sort of characters" ampersand gets escaped. Is there an easy way to do this? ...

Special mouse events in a browser: wheel, right-click?

Google maps is an impressive display of what you can do with javascript and Ajaxy-goodness. Even my mouse scroll wheel and right-click works to provide specific functionality. In the standard HTML spec, I don't see an "onmouserightclick" event or similar basic javascript handling for the mouse wheel. Maybe I am looking in the wrong pl...

How to pass a json url to a jquery function?

I have this loaded before the radio buttons with corresponding color variable. <script type="text/javascript"> //<![CDATA[ images = {"Black":"http:\/\/ecx.images-amazon.com\/images\/I\/31XwBA2m8pL.jpg","Slate":"http:\/\/ecx.images-amazon.com\/images\/I\/31SqWkrSb6L.jpg","White":"http:\/\/ecx.images-amazon.com\/images\/I\/31OJufgJT2L.j...

Where is that javascript tool that minifies the js files?

Hi, I can't find that tool that minifies that javascript. Its a java based tool. I thought douglas crawford made it, but can't find it on his site even! ...

creating a object in javascript that has a 'init' method with optional name/value pairs

I've seen many javascript objects that have a 'init' method that you pass in values to in order to setup the object. How do they internally handle the initializations of their private variables when passed in a array of name/value pairs like: myObject.init( {prop1: "blah", prop2: "asdf", ..., propn: "n"} ); Specifically, some ...

Paging Through XML Data Using jQuery and HTML

I've got an XML file that contains a list of questions. I'd like to load the first question in the list when an HTML page loads and load the answers as radio buttons. When one of the radio buttons is selected, I'd like to display the results as well as a continue button. The continue button would go to the second element in the XML file....

Creating a Survey using jQuery - Any examples?

I'm looking for a very basic survey/wizard example using jQuery and HTML. I'd like it to connect to a text file or XML file and be independent of SQL, PHP, ASP.NET, or any other scripting language outside of JavaScript. TIA UPDATE: I'm looking for a solution that will ask a single question at a time. Then, based on the multiple choice ...