CSTrüter HomeArticlesDownloadsAbout meContact me
How to enable the filestream feature in SQL 2008 - Alternative way to store blobs(files) via SQL 2010-08-21 19:31:56
How to create a Singleton Pattern in C# 2010-08-10 22:52:52
How to prevent that threads access shared resources concurrently via Monitor. 2010-08-06 15:31:15
A quick review of the book PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide written by Larry Ullman 2010-08-04 21:48:58
How to prevent that threads access shared resources concurrently via Mutex. 2010-08-03 14:42:36
How to stop propagation of javascript events 2010-07-25 21:59:29
Post about how Pete the web developer fixed his sitemap 2010-07-17 15:12:02
How to setup an out of process session service 2010-07-08 17:51:46
How to display/add images from/to a SQL Database 2010-07-04 23:15:15
How to register a custom URL protocol handler 2010-06-28 20:34:01
Creating a WYSIWYG textbox for your website is actually quite simple. 2007-02-01 12:00:00
Move items between two listboxes in ASP.net(C#, VB.NET) and PHP 2008-06-12 17:07:43
Firefox word wrapping issues 2008-06-09 09:51:21
Populate a TreeView control in a windows application. 2009-08-27 16:01:03
2007-02-22 12:00:00
Basics To get values from any html object via javascript, you will need to assign an id to your object - to reference it from the DOM. An easy way (and cross-browser friendly way) to retrieve the object is like this:
var Obj = document.getElementById('id')
<select name="dropdown" onchange="control(this)"> <option value="">Please Select</option> <option value="123">test</option> <option value="456">test2</option> </select>
Obj.value;
Obj.options[Obj.selectedIndex].text
Obj.options.add(new Option('text', 'value'))
Obj.remove(index)
Obj.options.length = 0
function move(fromID,toID) { var from = document.getElementById(fromID); var to = document.getElementById(toID); for (var i = 0; i < from.options.length; i++) { if (from.options[i].selected == true) { to.options.add(new Option(from.options[i].text,from.options[i].value)) from.remove(i); i--; } } }
<input type="button" onclick="shift('items', 'up')" value="Up" /> <input type="button" onclick="shift('items', 'down')" value="Down"/>
function shift(id, direction) { var items = document.getElementById(id); var oldIndex = items.selectedIndex; if (oldIndex != -1) { with (items) { if (direction == 'up') var newIndex = (oldIndex == 0) ? options.length - 1 : oldIndex - 1; else if (direction == 'down') var newIndex = (oldIndex == options.length - 1) ? 0 : oldIndex + 1; else return false; var a = new Option(options[oldIndex].text, options[oldIndex].value); var b = new Option(options[newIndex].text, options[newIndex].value); options[oldIndex] = b; options[newIndex] = a; selectedIndex = newIndex; } } }
re: "An easy way (and cross-browser friendly way) to retrieve the object is" Keep in mind that this method is broken in IE, and that you may (on more complex pages) run into issues if you are not very careful. See this page for info: http://webbugtrack.blogspot.com/2007/08/bug-152-getelementbyid-returns.html and http://webbugtrack.blogspot.com/2007/09/bug-154-getelementbyid-is-not-case.html
Thank you for your very valuable feedback Tyler What you're saying is indeed true, document.getElemenById isn't case sensitive at all (in IE), I don't want to defend Microsoft, but it isn't best practices to have anchors (and other elements for that matter) with the same names in your X/Html pages in anycase, even if they differ in case - this is a W3C standard, you'll even find a few IDEs that complain when you're trying this, VS2003/5 for example. http://www.w3.org/TR/html4/struct/links.html#h-12.2.1 So I don't really feel that document.getElementById is broken in IE (I believe Microsoft feels the same especially since they didn't really endeavor to "fix" this for the last hundred years) , I think its more a case of Microsoft interpreting how to enforce this standard in a different way than the mozilla codebase. You will find in IE that if you've got multiple anchors with the same name (including with different cases), that IE assumes that the first anchor with that identity, is the correct one - which forces the developer to adhere to this standard. In the mozilla codebase, they allow developers to ignore this standard - which isn't really a good thing at the end of the day. What is your feelings on this? I have to agree with Microsoft on this one (even though it makes me feel dirty saying it)
The company I am currently working for as software developer.
Collection of C# snippets 2010-05-22 01:06:19
Collection of MS SQL snippets 2010-05-22 00:55:15
Collection of JavaScript snippets 2010-05-22 00:37:57
Collection of ASP.net snippets 2010-05-22 00:29:56
Collection of PHP snippets 2010-05-22 00:06:45
a Parallel reference of programming languages 2009-09-10 12:48:23
a tutorial explaining how to develop a simple login using PHP and MySQL 2009-09-05 18:26:47
An article looking at adding some kind of event driven model to PHP 5 2008-07-28 12:48:09
It is very simple creating your own rss reader, the following article looks at a few methods of doing this. 2008-06-23 13:18:25
A quick reference about working with dropdown boxes (select element) in javascript. 2007-02-17 16:36:41
Collection of funny programming articles 2006-10-08 14:23:43