javascript

Is there a slicker way of doing this?

I seem to handle special cases like this somewhat frequently. There's got to be a more concise syntax or construct: var x = solveForX(); /* some slow calculation here */ if (x < 0) { x = 0; } This is equivalent, but doesn't feel any more elegant: var x; x = (x = solveForX()) < 0 ? 0 : x; Maybe there's a bit shift trick? Upda...

Unreliable javascript regex test in Firefox and Chrome

I am encountering a strange javascript regex problem on Firefox 3.6 and Chrome 6 dev. I am working on a massive form entry website that has some basic javascript validation using jQuery. $(document).ready(function() { $("tr[id^='" + BaseRowId + "rid']").each(function(){obj.WireRowEvents(this);}); } var obj = { "WireRowEvents": funct...

calculate text for a height, paginate the content

HI I am trying to paginate the content of UIWebview so i disabled the scroll then the second page will the current view height. The problem is sometimes the last line of page gets clipped so the first line of the next page too.I want a solution for this situation, if it occurs,it should left the line for the next page OR Is there any so...

formated text in textarea

IF I have a string <b>This Is In Bold Letters</b> then how can I include in a <textarea> so that the string appears in BOLD letters? using javascript & php? Pls help dear friends ...

Combining JavaScript files as recommended by YSlow - optimal size?

We have about 30 external JavaScripts on our page. Each is already minified. To reduce HTTP requests and page load time, we are considering combining them to a single file. This was recommended by the YSlow tool. Is this wise, or is it better to combine them into, say, two files with 15 scripts each? Is there an optimal size for the c...

Is there anyway to avoid an unterminated string literal error if I'm creating a string from an unknown source

I need to create a string in javascript from some text that the user provides. When I try to run this line: var str = new String('<%= @note.text %>') I get the unterminated string literal error. Given that I have no control over what is inputed, and I can't assign the string to start to do any character replacement, how do I fix this ...

is it possible to open a popup with javascript and then detect when the user closes it?

The question is pretty much all in the title. Is it possible (and how?) to open a popup with javascript and then detect when the user closes it? I am using jquery within the project so a jquery solution would be good. Cheers! ...

Is it possible to center a popup window using CodeIgniter's anchor_popup function?

I know how to center a regular popup window with javascript, but I can't get it to work with CodeIgniter's anchor_popup function. Here is my code $attributes = array( 'class' => 'blue-button', 'width' => '800', 'height' => '600', 'screenx' => '(window.width - 800) / 2', 'screeny' => '(window.he...

Get Tree Node name

I have a ASP.Net TreeView Control with Checkboxes along Child nodes. I want to get Text of the checked Child Node in the TreeView control. And I want to get the checked Child Node Text using jQuery/javascript. Mostly I had used jQuery in the page I had done. I had used $(this).text(). But its not working. Since the control is ASP.Net Tr...

Javascript/AJAX car make/model form

Hi guys, I am trying to create a car make/model form using Javascript or AJAX, problem is that I don't have a lot of experience with either, but here it goes. . . I need to create a form that has a car make and model drop down list in it, and when a user chooses a specific make, the model drop down will be populated with all of the mode...

Javascript "Object not a constructor" error when using namespaces?

I have the following JS code: window.Foo = {}; window.Foo.Name1 = function() { function Bar1(param1) { this.Name = param1; } } var gMyBar = new Foo.Name1.Bar1("hello world"); alert(gMyBar.Name); I'm getting the error "Foo.Name1.Bar1 is not a constructor" in my Firefox error console... what gives? ...

javascript (jQuery) not working in IE6

Hello all I have developed a dragable div with an image inside using jquery. The script is working perfectly in Firefox, chrome but not it IE6. could you please help me to fix this issue check the web page here : my web page Thank you very much for your consideration. ...

create custom window using iframe

Will any one please help me in creating custom window using iframe; that look likes the dialog or prompt box, but with new colors & images. ...

Get HTML of selected content

Hi, I have a UIWebView i want to introduce functionality of content(may be text or text and images) selection so that the user can email it. Is there any way to get the HTML code for the given selection using JavaScript? I tried the built-in clipboard of webkit but its seems not working for images selection.May be i am wrong,if there is ...

Sending GET and POST AJAX requests at the same time.

Hi there, i just would like to know if it is possible sending GET and POST AJAX requests at the same time and if it is how to do it using the XMLHttpRequest object. Thanks all for helping :D ...

JQTouch with JSON-Template or any other dynamic HTML generator: indexing child divs

Flat HTML files work fine with JQTouch. JQTouch goes out and indexes all the child divs. The problem is that using JSON-Template to dynamically builds the divs from after a page load, so JQTouch indexing doesn't happen, so navigation between divs doesn't happen. Does anyone have any suggestions? With other JS functions, converting stan...

Requesting something via ajax - how to stop other requests until this one is done

Hi, I have a php script that outputs json data. For the purposes of testing, i've put sleep(2) at the start. I have a html page that requests that data when you click a button, and does $('.dataarea').append(data.html) (php script returns a json encoded array. data.html has the html that i want to put at the end of <div class="dataare...

How can I dynamically name an array in Javascript?

I am using jQuery and JSON to pull data from a database. Each row of the database is a different product and each product has a number of properties associated with it. What I'm trying to do in js, is create a named array for each product containing all of the products properties. I know how to pull the data from JSON. I know how to con...

jQuery: Store additional/extra data/info inside a jQuery object?

Hello, Is it possible and smart to store extra data inside a jQuery object? Right now I have objects that contain some data but these objects also have a visual representation of that data. This works but I have a lot of code to keep them both in sync. For example if you delete an object from the dom I also have to delete the related...

Detecting when there is a response on an iframe?

I have created an AJAX style file download (using an iframe) and all works well... however, I need to detect when the iframe has received a response... see below: Javascript: function download() { var ifrm = $('#iframedownload')[0]; ifrm.src = '/downloadfile.aspx?fileid=whatever'; ifrm.onreadystatechange = function () { // Checki...