javascript

Assigning an ID to multiple "placeholding elements"

I have a JavaScript containing a text-input and some "placeholders". The script uses a function to display the value entered in the text-input in some placeholders. The problem is, that if I have to assign an ID to every single placeholder it will take a lot of time - I think avoiding duplication and repetition is called DRY So my quest...

jQuery making selection

I have a nested div like this <div id="one"> <div id="two"> id two goes here </div> <div id="three"> id three goes here </div> <div id="four"> id four goes here </div> </div> Now i want to handle click and doubleclick events on all divs except in div#four, like this $('#one').liv...

javascript: keep state of javascript effect

Hello, rookie here. i am using basic javascript, css to open/close div by clicking/unclicking on checkbox. function toggleMenu (divId, box) { var vis = (box.checked) ? "block" : "none"; document.getElementById(divId).style.display = vis; } how do i keep the state of the javascript effect. right now if i click on checkbox to o...

Using asp.net <%: %> syntax to generate javascript in an MVC application

I have a for loop to loop through my list of SliderItems which contain an ID, ImageUrl, and a link Url. <% foreach (var item in Model) { %> <a href="#"><img id="<%: item.ImageID %>" src="<%: item.ImageUrl %>" class="slide" alt="" /></a> <%} %> I need to loop through and generate the data parameters for this javascript automatical...

Why does my button need to be clicked twice for the event handler to work the first time, but thereafter just once?

I want the visitor to be able to expand/collapse some sections, and am using: <input onclick="return toggleDiv('xx')" type="button" class="button" value="click here to expand/collapse"/> and in the I have the function: function toggleDiv(a){ var e=document.getElementById(a); if(!e)return true; if(e.styl...

javascript switch depending on user type

I'm trying to make one registration form for two types of attendees that have different options for registration dates and price. Here's how I'm trying to set it up: They select their type: <SELECT id=StudentType name=StudentType> <OPTION id=0 selected value=0>Please Choose</OPTION> <OPTION id=freshman value=F>Freshman</OPTION...

$(this) in plugin options

I'm new to writing jQuery plugins, and I'm confused as to how to let users use $(this) in their options. As a simple (and redundant) example, say I wanted to let a user append their selection's text to an element they supply in their options, like so: $(function() { $('#stuff').appender({ 'placement' : this }); }); And the plugin c...

Scrolling the window during a jQuery animation

When the user clicks a certain button at the bottom of the site I am working on, it expands into a comment form. If there is a lot of other content on the page, the comment form will expand below the fold and the user might not notice that it has appeared. I would like to scroll the page down as the comment form expands to draw the user...

What is a neat way to vertically decrease opacity in a group of paragraphs of text in HTML

I am writing an application in rails. I have multiple paragraphs of dynamic text which are listed vertically. I am looking at neat way through javascript or CSS to vertically increase opacity of the group of paragraphs so the body of text has the appearance if disappearing as you go down the page. <p>Some text obviously more than i am...

regexp that selects only the capital letter from another regexp

I have this type of text: !D este caro 1 C este descgiderea C1 este alta deschidere Deschiderea de 1C este cu 2C 2D 3 D 1NT 2D 123456P This easy regexp: /([0-9][CDHS])/g selects "1C","2C","2D","2D" (a digit immediately followed by [CDHS], anywhere in the text) . What I want is to select only the letter from the sequences above...

JavaScript getting an elements class without any libraries

I would like to get the value of the class attribute for an element using JavaScript. However in this particular situation I don't have the luxury of library such as YUI, jQuery, etc. and need to stick to the basics. Specifically, I am looping over a table and want to check the class of the cell. I tried: var colClass = el.getAttribu...

Javascript progress animation

Hi, I am trying to build a progress bar using jQuery and javascript. It is basically a bar <div id="progressbar"><div id="progress"></div> <div id="number">0%</div> when you click on the next button (which isnt here) it changes the width of the progress div and using css3 it animates it nicely, but my problem here is the number. I ha...

How to declare global var in javascript and HTML?

How to declare a variable, I think global, the way I declare in an html file and then use it in a js file (included by <script> tags)? ...

Cross Browser Selection Range Library?

Does any one know of any cross browser user selection range libraries written in javascript? I have a found a few jquery plugins, (which quite frankly are too limiting and very buggy). I have already implemented and am using the following to pull off some of my tricks: http://plugins.jquery.com/project/wrapSelection http://perplexed.co...

Display php in divs using javascript.

Hello, I am trying to display different divs depending on a selection from a drop down menu. <html> <head> <title>DDlist Div Display</title> <script type="text/javascript"> function ShowDivArea(info) { var sel = document.getElementById('divArea').getElementsByTagName('div'); for (var i=0; i<sel.length; i++) { sel[i].style.displa...

Gotchas of JavaScript's Number type (C's double)

What are some important considerations for developers using JavaScript's Number type? I know it's an implementation of C's double type, but I'm a self-taught Python developer so that doesn't take me very far. Pointers to well-written articles will be great answers. Thanks! ...

Passing param to the OnLoad in aspx page from a javascript?

Hi guys, I have this javascript function myFunction(source) { window.open(source, "Title", 'width=400, height=400'); } and in c# code I call it by HtmlPage.Window.Invoke("myFunction", source); which opens up a aspx page and goes to its OnLoad function: protected override void OnLoad(System.EventArgs e) { b...

How to calculate the XPath position of an element using Javascript?

Let's say I have a large HTML file with different kinds of tags, similar to the StackOverflow one you're looking at right now. Now let's say you click an element on the page, what would the Javascript function look like that calculates the most basic XPath that refers to that specific element? I know there are an infinite ways of refer...

jquery table select and data retrieval

I am using a html table that contains available times for scheduling. I want the user to be able to click on a time and from that be able to get the column header, which is the staff persons name, and the value of the cell - the time. I than want to change the contents of the cell to 'NA' and set the cell background to some color. I h...

list of shorthand css properties

A JavaScript function I made needs to parse all CSS values that don't necessarily have 'one' value attached to them. For example, margin:0 0 4px 12px; is actually four values (margin-top, margin-right, etc). Basically, all I need is a list of the shorthand properties. However, I don't need all shorthand css. I just need the shorthand cs...