javascript

JavaScript function in PHP page causing issues with PHP tabs format

I am trying to reference a JavaScript file, containing a table sort function, in a PHP file. Everything functions the way it should, but once I add the code below to my PHP report page it causes issues with the format of the tabs on my navigation page. The same issue comes up if I add a random document.write outside of the PHP code. Not ...

Ruby variable in :with of observe_field

I need to send a class name with my observe_field call so I can update the correct text_field (there are multiples on the same page) <%= observe_field "songlists_" + section.id.to_s + "_song_name", :frequency => 0.5, :url => { :controller => :songlists, :action => :get_artist }, :update => text_class , :with => "'song_name=' +enco...

iframe problems

I have a page that has an embedded iframe doing ajax requests.... when i click on a link i want the new link to open up in the main window and not the iframe which it is doing right now... i tried doing this in javascript window.parent.location.href = url of link doesnt work... anyone out there with a better idea to do this??? also i ...

Iterating through a html array in javascript

Hi I have sevral selects on my page with the name viewer[]. In javascript I wish to iterate through this array and get each ones selected index. var welements = document.getElementsByName('viewer[]')[0]; for ( var i in welements ) { alert(i.selectedIndex); } I have above but its clearly wrong. I beleive th...

JS Events: hooking on value change event on text inputs

Hi all, I have a text input that its content is changed by a script not by user. So I would want to fire an event when the value changes. I can't find a suitable event for that. I event found this on StackOverflow but is not the solution I'm looking for. How to make this work with jQuery and a text input where the value is set like thi...

Why does my javascript Catch block not execute?

I feel silly asking this, I must be missing something obvious. My javascript looks as follows... function onNewItemClick(event) { alert('ello!'); try { var xx = 111/0; } catch(exc) { alert('fff'); } } alert('ello!') works like it should, but the alert('fff') in the Catch block never gets called...

What is the best way to keep track of the id of an element selected from an auto-suggest textbox?

I have an auto-suggest textbox. A user can either pick an already existing item in the database of type in a new one. How do i keep track of the id if item was selected (Store the id of the list of items coming from the db)? ...

Organising top level functions in a Javascript file

Occasionaly we will have a page that required some page specific Javascript functionality. I will create a javascript file called myPageName.js. The question I have is how do people organise their top level functions. I currently have 15+ top level functions defined like this function function1 (containerElement) { ...do function1;...

Css Html JavaScript - Navigation Highlight current selected Menu

Hello, i think this question is very easy but I don't know if i am right. I am an oldschoool html, php coder. I want to use this kind of navigation: http://www.cssportal.com/horizontal-menus/13styles.htm So far no problem. I got an dynamic php page and i want to use this Menu. There is no problem without this line in the HTML Part: ...

JSON Variable showing as text

I am not too savvy with JSON so any help would be great... I am loading a page via JQuery's .load. I am setting varname as a variable, but it is posting as the actual variable name not what I set it to. In other words it is showing up as "varname" instead of "class_id". var varname = "class_id"; $(this).siblings(".container").load(l...

variable-variables inside function scope

Before you ask... I don't plan to actually do this. It's bad practice for obvious reasons. I'm just curious if it is possible. In javascript, you can use bracket syntax to make variable-variables in global scope: var var_name = 'my_var', var_value = 'my_value'; window[var_name] = var_value; alert( my_var ); // Works! alerts user...

Duplicating an element (and its style) with JavaScript

Hello, For a JavaScript library I'm implementing, I need to clone an element which has exactly the same applied style than the original one. Although I've gained a rather decent knowledge of JavaScript, as a programming language, while developing it, I'm still a DOM scripting newbie, so any advice about how this can be achieved would be...

loop through tr's with Jquery and compare contents with next row in series

I'm somewhat new to jQuery/javascript, and would like to compare the contents of row[i] in a table body with row[i+1]. Is this something I can do with jQuery or should I just use plain old JS and getElementByid and then loop that way? using the .each doesn't appear to give anyway of accessing the next element in the series easily. I a...

IE 7 textarea breaks between words

Hi all, I've got a LAMP site with a form that a user fills out. For some reason if viewing the returned form submission data on IE 7, it's inserting line breaks between each word. It's a pretty basic form with some input elements and a text area. If I submit the form with FF3+, IE8, or safari this isn't happening and everything looks f...

How do I set a User field to a SystemUserId in JavaScript?

I'm customizing a form in Microsoft's CRM Dynamics Online, and need to set a field value to the current users's ID. I've got code that correctly pulls the SystemUserID, but I'm having difficulty getting the value into the form field. //Lots of XML/SOAP stuff to pull the user information var systemUserIdNode = entityNode.selectSingleNod...

Why does .html work and not innerHTML or appendChild

Hey! I am trying to add an ajax response to a div (it's htmlcode, tables, forms etc). In FF innerHTML works perfectly, but in IE it gives me an unknown error. I tried lot's of stuff, but I only got it working when I added jQuery and ran the .html method on the div I want the code inserted into. Anyone care to explain why this works ...

JavaScript decorators HOWTO?

Hi all, I need to decorate a 3rd party function that I can't modify so I will need to decorate it in any way. I found that in Prototype there is something to do it easily [1]. Is there any alternative to that in jQuery or in plain JavaScript? [1] http://api.prototypejs.org/language/function.html#wrap-instance%5Fmethod ...

Where to begin with Smartphone Web Development?

Ha all, So I've been taksed with developing a smartphone website for our property portal and first thing I did was see what lessons others had to tell online but I've found very little. I'm not building an app, I'm building a website and I'm looking for do's and don't with regards to html, css, widths/heights approaches, javascript (is...

Programatically trigger an onclick event?

I am trying to simulate an asynchronous file upload using an iframe. Here is my markup: <form method="POST" enctype="multipart/form-data" name="change-avatar" action="/dyn/actions/upload?type=profile" target="target-upload"> <input type="file" name="change-avatar-input" style="position: absolute; z-index: 999; cursor: pointer; left: 10p...

Trying to create a click method for a div, doesn't work in IE6?

I made a simple div: <div id="foo"></div> and I added a click method to it in jquery $("#foo").click(wow); function wow(){ alert("Message"); } This works fine in Firefox/others, but doesn't work in IE6/IE7? Why? Any specific resources on this? Edit: The Div already exists in the dom, and the jQuery is run on ready, and it still...