<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
	<title>Professional Web Development Forums - Tutorials</title>
	<link>http://www.prowebforums.com/index.php?app=tutorials</link>
	<pubDate>Mon, 15 Mar 2010 20:00:30 +0000</pubDate>
	<ttl>1800</ttl>
	<description>Tutorials from all available categories.</description>
	<item>
		<title>CSS Table Borders</title>
		<link>http://www.prowebforums.com/tutorials/article/1-css-table-borders/</link>
		<description><![CDATA[If you want to add a 1px border around every cell in a table, it can be a little confusing. If each cell has a border of 1px, then the borders of cell #1 and cell #2 will be next to each other, and make the border appear to be 2px.<br />
A common way I've seen to get around this is to do:<br />
<br />
<pre class='prettyprint'><table><tbody><tr><td style="background-color : #000000;">
<table cellspacing="1">...rows/columns...</table>
</td></tr></tbody></table></pre>This will make a 1px gap appear between each cell, then display the black background behind it, making it appear to be a black 1px border. This is simply ugly, and not XHTML, as it requires an unnecessary table.<br />
To do this in XHTML, it requires a bit of CSS. I don't think this will be useful if you intend to use some extravagant combination of borders, but a simple 1px single-color border will work perfectly.<br />
<br />
First, set up your table:<br />
<br />
<pre class='prettyprint'><table cellspacing="0">...rows/columns...</table></pre>We use a 0 cell spacing, because we don't want a gap between the cells. We're using <em class='bbc'>actual</em> borders, so they need to connect.<br />
<br />
<br />
In CSS:<br />
<pre class='prettyprint'>/* border color and style for the table */
table, td, th {
    border-color : #000000;
    border-style : solid;
}</pre>This will set up the color and style used. Adding them all the to the same definition, instead of defining table, td, and th separately, will allow them to be modified quickly and efficiently if you ever decide to change the color or style of the border.<br />
<br />
<br />
In CSS:<br />
<pre class='prettyprint'>/* the widths of the border */
table {
    border-width : 1px 0 0 1px;
}
td, th {
    border-width : 0 1px 1px 0;
}</pre>This will give all the columns a border on the right and bottom. Where do the top and left border come from? Well, if the column isn't a very top column, it will get its aesthetic top border from the column above it's bottom border. If it isn't a far right column, it will get its aesthetic left border from the column to the left of it's right border.<br />
If the column <em class='bbc'>is</em> the very top and/or far left column, then it will get its top and/or left border(s) from the table.<br />
<br />
~ Hope that helps some of you with your table design. ~<br />
<br />
Example here: <a href='http://emulation.gamingmedley.com/patches.php' class='bbc_url' title='External link' rel='nofollow external'>emulation patches</a>]]></description>
		<pubDate>Tue, 21 Apr 2009 17:26:13 +0000</pubDate>
		<guid isPermaLink="false">1</guid>
		<creator>GamingMedley</creator>
		<category>2</category>
	</item>
	<item>
		<title>Form Manipulation</title>
		<link>http://www.prowebforums.com/tutorials/article/6-form-manipulation/</link>
		<description><![CDATA[<strong class='bbc'>Form Manipulation</strong><br />
<br />
<strong class='bbc'>Note:</strong> Before reading this tutorial, you should have a general understanding of most of the possible uses of items in a form. All general and simple items. Also, I will not be doing anything with uploads. Nothing really to do with them. I also will not cover radios, since they're a mixture between a select and a checkbox and can be figured out easy enough if you understand them. Lastly, for all examples we will be pretending that they are inside the following form:<br />
<br />
<pre class='prettyprint'><form name="testForm" id="testForm" action="index.php" method="get">
   <!-- Form items here -->
</form></pre><br />
<br />
<strong class='bbc'>Accessing the Form and Form Items</strong><br />
This is a basic concept that needs to be explained. First off, we need to assign a name to the form we want to access. The example form already has the name of "testForm," so we'll take advantage of that. We're going to access it via the document object.<br />
<br />
<pre class='prettyprint'>var theform = &#100;ocument.testForm;</pre>Now that we have the form, we want to access an element inside the form. Each element in a form <strong class='bbc'>should</strong> have a name assigned to it, though sometimes they won't. In this case, let's assume we want to access the element with the name "formitem1."<br />
 <br />
<pre class='prettyprint'>var theform = &#100;ocument.testForm;
var formitem1 = theform.formitem1;</pre>Now that we've got access to the form item, we could perform any operation on it that we want. Let's say we want to find a element who's value matched "foo," but we didn't know the name of it. We'd use the "elements" array.<br />
<br />
<pre class='prettyprint'>var theform = &#100;ocument.testForm;
var eles = &#100;ocument.testForm.elements;
for(var a=0;a<eles.length;a++){
   if(eles&#91;a&#93;.value.match(/foo/i)){
      var theele = eles&#91;a&#93;;
      break;
   }
}</pre>Make sure to note that this assumes that an element would match "foo," otherwise you could encounter errors.<br />
<br />
Now, it is possible to perform a similar search through forms. Let's say we know a form contains "bar" in the name, but we aren't sure of the exact name. We could search through the forms property of the document object.<br />
<br />
<pre class='prettyprint'>var tosearch = &#100;ocument.forms;
for(var a=0;a<tosearch.length;a++){
   if(tosearch&#91;a&#93;.name.indexOf("bar") != -1){
      var theForm = tosearch&#91;a&#93;;
      break;
   }
}</pre>I'm not going too far into detail on these, as they aren't a fairly important part of this tutorial, despite being helpful.<br />
<br />
<strong class='bbc'>Note:</strong> There are numerous ways to access a form or form elements. I've only explained a few.<br />
<br />
One last thing I want to mention before moving into the actual tutorial. You can use the "form" property of a form element to obtain the form for that element. For example, "checkbox.form" would return the form that contains a checkbox.<br />
<br />
<br />
<br />
<br />
<br />
<strong class='bbc'>Input - type="text"</strong><br />
Let's start off with the most basic, of the basic. An input with type="text". For this example, we'll be using this input:<br />
<br />
<pre class='prettyprint'><input type="text" value="Default Value" name="inputtext" id="inputtext" maxlength="15" /></pre>First off, we're going to cover the basics of grabbing information that a user enters. Whenever a user enters information, it is sent into the "value" property of the input. So, taking the default input, if we alerted the value of &#100;ocument.testForm.inputtext.value, we'd get "Default Value" since that's the current value.<br />
<br />
Let's take a look at making a simple "Click on this and the text inside disappears, but if blank reappears." In this case, we're going to work with simple events and we'll be making this similar to something that one might use if a search box.<br />
<br />
<pre class='prettyprint'><input type="text" value="Search" name="searchBox" id="searchBox" maxlength="100" />
<script type="text/J&#097;v&#097;script">
var theBox = &#100;ocument.testForm.searchBox;
theBox.&#111;nfocus = function(){
   if(this.value == "Search"){
      this.value = "";
   }
}
theBox.&#111;nblur = function(){
   if(this.value.length == 0){
      this.value = "Search";
   }
}
</script></pre>Now, let's break down the code. First off, we have our input itself. Then, we move to the script tag. The third line grabs the search box itself. Now we get to where we assign the events that will manage the clearing of and filling in of the "Search" text. We're using two basic events functions: &#111;nfocus and &#111;nblur. &#111;nfocus activates whenever the object in question obtains the focus of the user. &#111;nblur activates whenever the object in question loses the focus of the user. (Note that it doesn't activate if the item did not already have the focus of the user.) We assign two simple events and then in the events, we check specific properties of the value, and then change value depending on if the check returns true. This is a basic, and quite straightforward method of doing a box that auto-clears itself. You could also have assigned the events inline in the input tag. These inputs also support the "disabled" property via j&#097;v&#097;script (input.disabled = "true") and are used with that for a characters left item typically. Disabled elements can have their values changed by a script, but not by the user.<br />
<br />
Another quick note: type="hidden" inputs generally share a similar usage to type="text", except that they have no disabled property since they aren't visible.<br />
<br />
<br />
<br />
<br />
<br />
<strong class='bbc'>Input - type="checkbox"</strong><br />
Checkboxes are some of the most useful form items, then again, all of them are useful really. There's only three things that really need to be mentioned: the "checked" property, the "disabled" property, and the "click" function. checkbox.disabled works in the same way as it does with a type="text" element, so we'll skip right to the "checked" property.<br />
<br />
checkbox.checked is a boolean value and you can use it to either change whether or not the checkbox is checked or you can use it to check if the box is checked. Those are the basic uses. You never need to use the "value" property of a checkbox, because it returns "1" whether it is checked or not.<br />
<br />
checkbox.click() is the last useful function of a checkbox. What it does is act as if the user clicked on the checkbox. Assuming the box is enabled, it is the same as saying "checkbox.checked = !checkbox.checked" which would invert the value of it being checked. If the box is disabled, it does nothing.<br />
<br />
<br />
<br />
<br />
<br />
<strong class='bbc'>Input - type="submit" - type="button" - type="reset"</strong><br />
Oh joy, the buttons of forms. At this point, I assume you know what each button does by itself. There's not much else to discuss on these buttons besides mentioning that they support the "disabled" property and that doing anything with their "value" property will update the text on the button. I'll give an example of a helpful function/event to use on your buttons in a script however. <br />
<br />
<pre class='prettyprint'><input type="submit" value="Submit" &#111;nclick="disable(this.form);" />
<script type="text/J&#097;v&#097;script">
function disable(f){
   if(!f.nodeName || f.nodeName.toLowerCase() != "form"){ // Makes sure the element provided is a form.
       return false;
   }
   for(var a=0;a<f.elements.length;a++){
      if(f.elements&#91;a&#93;.nodeName.toLowerCase() == "button" || (f.elements&#91;a&#93;.nodeName.toLowerCase() == "input" && f.elements&#91;a&#93;.type.match(/^(submit|reset|button)$/i))){
         // Disable elements if it's a button, or a input with type="submit", type="reset", or type="button"
         f.elements&#91;a&#93;.disabled = true;
      }
   }
}
</script></pre>I will not break down this code, as you should be able to understand it just by having read this tutorial. I did however leave two comments to help you out.<br />
<br />
<br />
<br />
<br />
<br />
<strong class='bbc'>Textareas</strong><br />
A textarea is one of the stranger form elements. Despite being setup without a value property in the HTML and making it look like innerHTML would return whatever is between the <textarea> and </textarea>, it doesn't. What is between those two tags is actually the value property. You can change this property, but it is recommended that you do not attempt to ever change the innerHTML of a textarea, unless you want to experience some weird changes to your webpage.<br />
<br />
Also, textareas support the "disabled" method, which can come in handy.<br />
<br />
<br />
<br />
<br />
<br />
<strong class='bbc'>Selects</strong><br />
Note that I'm not going to cover selects with multiple="multiple", just a basic select. To begin things off, selects support the disabled property. Also, for all examples, we'll be using the following select:<br />
<br />
<pre class='prettyprint'><select name="theSel" id="theSel">
   <option value="opt1">Option 1</option>
   <option value="opt2">Option 2</option>
   <option value="opt3">Option 3</option>
</select></pre>As you can see, we have three options within our select. If we were to alert the "length" property of our select, it'd return 3 since there's three options. We can also use this method to access the options. For example, &#100;ocument.testForm.theSel[0] would return a node reference to the first option. You can also access options through the "options" property, which happens to be an array.<br />
<br />
Now, let's figure out how to get the value. Calling the "value" property on the select will return the value, and you can set the value this way too. But setting the value that way has problems. For example, if you attempt to set the value to something that doesn't have a corresponding option with that value, it won't update the select at all. This is where we're going to mention selectedIndex. selectedIndex is a property that contains a number corresponding to the placement of the currently selected option in the theSel.options array. So, theSel.options[theSel.selectedIndex].value is the same as theSel.value.<br />
<br />
selectedIndex is most useful when having to reorder or remove items from a select. Say for example, you want to remove an item from a select once a user selects it. The code might look like this.<br />
<br />
<pre class='prettyprint'><select &#111;nchange="this.removeChild(this.options&#91;this.selectedIndex&#93;); this.selectedIndex=0;" name="theSel" id="theSel">
   <option value="opt1">Option 1</option>
   <option value="opt2">Option 2</option>
   <option value="opt3">Option 3</option>
</select></pre>That way when you remove the select, if you don't know the value of the first item, you can still set it to that item. This code itself would have problems since you couldn't select to remove the first item, but that's something we'll fix another day.<br />
<br />
Now we're going to delve into adding, removing, and checking the selection on options. To add an option, it is easiest to use a simple DOM method.<br />
<br />
<pre class='prettyprint'><script type="text/J&#097;v&#097;script">
var theSel = &#100;ocument.testForm.theSel; // Grab the select
theSel.appendChild(&#100;ocument.createElement("option")); // Create the option
theSel.lastChild.value = "opt4";  // Since we appended the option, it is the last child of the select.
theSel.lastChild.innerHTML = "Option 4"; // Set the innerHTML. Can also be referenced with "data"
</script></pre>Now we've created an option, we can also remove it.<br />
<br />
<pre class='prettyprint'><script type="text/J&#097;v&#097;script">
var theSel = &#100;ocument.testForm.theSel; // Grab the select, again.
for(var a=0;a<theSel.length;a++){ // Loop through the options
   if(theSel&#91;a&#93;.value == "opt4"){ // Check the value
      theSel.removeChild(theSel&#91;a&#93;); // Remove the child.
      break; // Found it. Break loop.
   }
}
</script></pre>That's a nice easy way to remove an option from the select. Now, let's try removing the option only if it's selected. I'll show two methods.<br />
<br />
<pre class='prettyprint'><script type="text/J&#097;v&#097;script">
var theSel = &#100;ocument.testForm.theSel; // Grab the select, yet again.

// METHOD 1
for(var a=0;a<theSel.length;a++){ // Loop through the options
   if(theSel&#91;a&#93;.selected == true){ // Check if selected
      theSel.removeChild(theSel&#91;a&#93;); // Remove the child.
      break; // Found it. Break loop.
   }
}

// METHOD 2
theSel.removeChild(theSel.options&#91;theSel.selectedIndex&#93;);
</script></pre>Both ways of removal work equally well. This concludes the select section.<br />
<br />
<br />
<br />
<br />
<br />
Well, hopefully this tutorial helped some future coders out there to learn the basics of form manipulation. :P There's much more that can be done, but this will at least help you get a basic understanding and set you on your way to manipulating basic forms. If you need any help, feel free to post/comment.]]></description>
		<pubDate>Tue, 03 Mar 2009 07:39:33 +0000</pubDate>
		<guid isPermaLink="false">6</guid>
		<creator>cddude229</creator>
		<category>4</category>
	</item>
	<item>
		<title>document.createAttribute()</title>
		<link>http://www.prowebforums.com/tutorials/article/5-documentcreateattribute/</link>
		<description><![CDATA[<strong class='bbc'>&#100;ocument.createAttribute()</strong><br />
<br />
A long time ago (see: 2005), I released a tutorial covering this same subject. However, I decided it's time to completely revise the tutorial and actually correct the numerous mistakes I had on this function. So, here we go...<br />
<br />
To begin with, &#100;ocument.createAttribute() is similar to the DOM functions of &#100;ocument.createElement(), &#100;ocument.createDocumentFragment(), and &#100;ocument.createComment(). It creates an "attribute" node as opposed to an element node (createElement), a document fragment (createDocumentFragment), or a comment node (createComment) however. Seeing a pattern yet? I see one.<br />
<br />
I will not discuss what an attribute node is since it is fairly straight forward if I just show this example:<br />
<pre class='prettyprint'><td attribute="value_of_attribute">cell content</td></pre>A quick thing to mention is that the nodeType of an attribute node is 2. The most amazing part is that both IE and Fx recognize this. IE conforming to standards? Amazing, I know.<br />
<br />
Anyways, back to the task at hand. &#100;ocument.createAttribute() is most commonly used as an alternative to element.setAttribute("name", "value"); It's a bit longer, but is more of a true DOM method. I'll now show you an example of usage and then break it down for you. (Also, Code 1 and Code 2 are essentially equivalent.)<br />
<br />
<pre class='prettyprint'>// Code 1:
var newAttr = &#100;ocument.createAttribute("attrname");
newAttr.nodeValue = "new_value";
element.setAttributeNode(newAttr);

// Code 2:
element.setAttribute("attrname", "new_value");</pre>BREAK IT DOWN... no seriously, I'm going to break this code down for you guys. :P<br />
<br />
<pre class='prettyprint'>var newAttr = &#100;ocument.createAttribute("attrname");</pre>Well, this line is straight forward mostly. We're creating a new attribute node and assigning it to a variable for reference.<br />
<br />
<pre class='prettyprint'>newAttr.nodeValue = "new_value";</pre>Now that we've created the attribute, it kinda needs a value. We alter this using the nodeValue property. Assign it to whatever you want the new value to be.<br />
<br />
<pre class='prettyprint'>element.setAttributeNode(newAttr);</pre>And here we finally set the attribute node into the actual element. If we were to use getAttribute("attrname") on this element now, we'd find the value of "new_value" that we just recently assigned to it.<br />
<br />
<br />
That's really all there is to &#100;ocument.createAttribute(). Honestly, I'd recommend using the alternative setAttribute() method, but this one can work just as well (besides taking up a bit more script room.)]]></description>
		<pubDate>Tue, 03 Mar 2009 07:37:10 +0000</pubDate>
		<guid isPermaLink="false">5</guid>
		<creator>cddude229</creator>
		<category>4</category>
	</item>
	<item>
		<title>JavaScript Cookies</title>
		<link>http://www.prowebforums.com/tutorials/article/4-javascript-cookies/</link>
		<description><![CDATA[<strong class='bbc'>Cookies</strong><br />
<br />
This tutorial will cover a few basic things about cookies, including setting and updating a cookie, grabbing the cookie's value, and deleting a cookie. Take note that there are a few things I won't bother mentioning, such as the extra, optional properties you can use or things like the expiration date being optional and it becoming a session cookie if left off.<br />
<br />
To start off, we'll be covering how to set a cookie. Let's take a look at the basic syntax for one.<br />
<br />
<span style='color: blue'>&#100;ocument.cookie = </span>"<span style='color: red'>NAMEHERE=</span><span style='color: orange'>VALUEHERE;</span> <span style='color: green'>expires=</span><span style='color: purple'>DATE</span>";<br />
<br />
Starting with the colors, here's a break down. (Note: All non-colored parts are just designating the end of a line, a space, or a quote.)<br />
<br />
<span style='color: blue'>Blue</span> - This is designating the fact that we're setting a cookie. The cookie is a property of the document object, so first we grab it. Then we add an equals sign saying we're setting it equal to something, but a cookie behaves differently. It actually is saying we're updating the cookie property with this specific cookie.<br />
<span style='color: red'>Red</span> - This starts off by saying that we're about to designate the name of the cookie. The equals sign denotes the end of the cookie's name.<br />
<span style='color: orange'>Orange</span> - This is the value. Everything up until the semi-colon is the value of the cookie. If you want to use a semi-colon in the value, escape() or encodeURIComponent() it first. (Make sure to unescape() or decodeURIComponent() it when retrieving the value.)<br />
<span style='color: green'>Green</span> - This is saying that we're about to set the expiration date of the cookie.<br />
<span style='color: purple'>Purple</span> - This is the date the cookie will expire on. For this, its easiest to use JS Date object and then call toGMTString() upon the object. You can use set time to accordingly adjust the time to what you want it to be.<br />
<br />
Now that we have the layout for it down, let's give a few examples.<br />
<br />
<pre class='prettyprint'>var d = new Date();
d = d.toGMTString();
d = d.replace(/d{4}/,"2050");
&#100;ocument.cookie = "cookiesrock=Yes they do;expires="+d;</pre>Taking a look at it line by line, you'll get a general idea of how this works.<br />
<br />
<pre class='prettyprint'>var d = new Date();</pre>We create a new date object. This is needed to get the date format we want.<br />
<br />
<pre class='prettyprint'>d = d.toGMTString();</pre>This takes the date object and turns it into a string, technically, a string in the GMT format and time zone.<br />
<br />
<pre class='prettyprint'>d = d.replace(/d{4}/,"2050");</pre>Now we're going to replace the first match of 4 numbers in the date string with "2050". What gets replaced is the year actually, so we're setting this cookie to expire in the year 2050.<br />
<br />
<pre class='prettyprint'>&#100;ocument.cookie = "cookiesrock=Yes they do;expires="+d;</pre>This line just creates the cookie, which you should have gotten from the break down before. You can also see where d (the date object converted) is used in the code.<br />
<br />
<br />
<br />
Now that we've covered the basics of setting a cookie, I'm going to tell you that updating a cookie is done the exact same way. So yes, you just learned two things at once. Have fun with that. =)<br />
<br />
<br />
<br />
Moving on, we're going to cover grabbing the value of a cookie. Let's use these cookies as an example.<br />
1. cookiesrock=Yes they do<br />
2. woot=Whee<br />
3. smilies=\m/ >.< \m/<br />
<br />
If you alert the &#100;ocument.cookie object, you'll get a string that looks something like this:<br />
<pre class='prettyprint'>cookiesrock=Yes they do;woot=Whee;smilies=m/ >.< m/</pre>Note that they removed the dates you might have inserted. You might think this is annoying, but in the case of grabbing data, its quite useful. If you look, you see the data is all there, but we need someway to grab it. I prefer the RegExp. method personally, so I'll be teaching that.<br />
<br />
<pre class='prettyprint'>if(&#100;ocument.cookie.match(/woot=(.+?)(;|$)/)){
      var cookievalue = RegExp.$1;
}</pre>Looking at a quick break down of that, you'll see I'm checking &#100;ocument.cookie to match the RegExp /woot=(.+?)(;|$)/. Then if its matched, I assign the first RegExp parenthetical match to cookievalue. This effectively just grabbed the cookie's value for you.<br />
<br />
<br />
<br />
<br />
Moving on to deleting cookies. Deleting a cookie is as easy as setting one, literally. Set the value of the cookie to a blank (put the semi-colon following the equals sign right away), and then set the expiration date for some time in the past. =)<br />
<br />
<br />
Now that I've covered the basics of cookies, here's some helpful little functions that you may use. They might save you a bit of time when developing your codes.<br />
<br />
<br />
<pre class='prettyprint'>function setCookie(_name,_value){
    &#100;ocument.cookie = _name+"="+escape(_value)+";expires="+(new Date()).toGMTString().replace(/d{4}/,"2050");
}

function getCookie(_name){
    if(&#100;ocument.cookie.match(new RegExp(_name+"=(.+?)($|;)","gi")))
        return unescape(RegExp.$1);
    return null;
}

function getCookie2(_name){
    if(&#100;ocument.cookie.indexOf(_name) == -1)
        return null;
    var _c = &#100;ocument.cookie.substring(&#100;ocument.cookie.indexOf(_name));
    return unescape(_c.substring(_c.indexOf("=")+1,(_c.indexOf(";") == -1?_c.length:_c.indexOf(";"))));
}

function deleteCookie(_name){
    &#100;ocument.cookie = _name+"=;expires="+(new Date()).toGMTString().replace(/d{4}/,"2004");
}</pre>]]></description>
		<pubDate>Tue, 03 Mar 2009 07:35:45 +0000</pubDate>
		<guid isPermaLink="false">4</guid>
		<creator>cddude229</creator>
		<category>4</category>
	</item>
	<item>
		<title>rowIndex and cellIndex</title>
		<link>http://www.prowebforums.com/tutorials/article/2-rowindex-and-cellindex/</link>
		<description><![CDATA[<strong class='bbc'>rowIndex and cellIndex</strong><br />
<br />
Its that time again. Time to learn about some of the most useful properties that you may not have known about. The kinds of properties that will make you say "Oh my god, how did I not know that before?! This will make my code so much faster!"<br />
<br />
This tutorial covers the two properties that belong to rows and cells: rowIndex and cellIndex respectively.<br />
<br />
First question that probably comes to mind is: "What do they do?" Well, what they do, is they tell you where a row/cell is in the parent object. Specifically, they tell you what row or what cell they are in the parent (remember, J&#097;v&#097;script starts counting at zero however).<br />
<br />
The next question may be: "How is this useful?" Well, there's a few things that I've found this useful for. Here's a brief list:<br />
1. Use with insertRow and insertCell to insert a row/cell before/after the current one.<br />
2. Use with deleteRow and deleteCell to remove the current one or remove one that is before/after the current one.<br />
3. Use with moveRow (IE only) to move a row before/after the current one.<br />
<br />
As you can see, it has its uses, just like every J&#097;v&#097;script function/object/method/property. The uses just need to be found.<br />
<br />
Now, let's take a look at an example of how this could be used. Here's an example table.<br />
<br />
<pre class='prettyprint'><table border="1">
<tr id="row1"><td>Cell 1</td></tr>
<tr id="row2"><td>Cell 2</td></tr>
<tr id="row4"><td>Cell 4</td></tr>
</table></pre>Now, let's analyze this. We'll notice that "row3" is missing. Now, we want to insert this row to fix this. But, let's say this table is dynamically generated via PHP (just for usage's sake). We'll say we know row3 is never there, but row2 and row4 are always there, and sometimes other rows are there (row0, row1, row5, row6, etc.)<br />
<br />
We need a quick and easy solution to insert a new row without constantly looping through all the rows. Not to mention, it'd be a bit harder since the table doesn't currently have an ID.<br />
<br />
Now, since I've explained the basic usage for rowIndex, let's use it to insert row3 and "Cell 3". Our script will look something like this:<br />
<br />
<pre class='prettyprint'>var r2 = &#100;ocument.getElementById("row2"); // Grab "row2"
var r3 = r2.parentNode.insertRow(r2.rowIndex+1); // Insert "row3"
r3.id = "row3"; // Assign the ID to be consistent
var c3 = r3.insertCell(0); // Insert the cell
c3.innerHTML = "Cell 3"; // Add the cell's innerHTML</pre>Now, how about a break down for you guys?<br />
<br />
<pre class='prettyprint'>var r2 = &#100;ocument.getElementById("row2");</pre>First off, we need to get our row to call rowIndex off of. We use this to grab the row.<br />
<br />
<pre class='prettyprint'>var r3 = r2.parentNode.insertRow(r2.rowIndex+1);</pre>Now, let's use rowIndex to insert a row after our current one. We first need to grab the tbody/table element to use insertRow on, then we need to get the rowIndex+1 for where the cell would be inserted.<br />
<br />
<pre class='prettyprint'>r3.id = "row3";</pre>This part could just as easily be removed from the code. I only did this to be consistent.<br />
<br />
<pre class='prettyprint'>var c3 = r3.insertCell(0);</pre>Now, we're going to insert our cell into "row3".<br />
<br />
<pre class='prettyprint'>c3.innerHTML = "Cell 3";</pre>And now, we insert the innerHTML for "Cell 3".<br />
<br />
So there's one method of doing it. There is an alternate method that could be used. That method uses "row4" instead of "row2" to insert the row, but it doesn't matter which you use. They'd produce similar results.<br />
<br />
Anyways, hope this helps some of you guys. Enjoy. :)]]></description>
		<pubDate>Tue, 03 Mar 2009 07:32:55 +0000</pubDate>
		<guid isPermaLink="false">2</guid>
		<creator>cddude229</creator>
		<category>4</category>
	</item>
	<item>
		<title>insertRow and insertCell</title>
		<link>http://www.prowebforums.com/tutorials/article/3-insertrow-and-insertcell/</link>
		<description><![CDATA[<strong class='bbc'>insertRow and insertCell</strong><br />
<br />
One of the most common questions among beginners is this: "How do I insert a new row to the table?" And the answer? Simple. "Use insertRow and insertCell."<br />
<br />
But what are these? Well, that's what I'm here to tell you. insertRow and insertCell are methods used to create new cells and rows in a table (or tbody technically). Let's start with a breakdown of how both are used and then we'll move onto an example.<br />
<br />
First off, insertRow and insertCell are methods. Meaning, they are called off of an object. For a row, it'd be a tbody or table element. For a cell, it is a row. Let's take a look at the following syntax examples:<br />
<br />
<pre class='prettyprint'>tableobject.insertRow(insertionpoint);
tbodyobject.insertRow(insertionpoint);
rowobject.insertCell(insertionpoint);</pre>Both insertRow and insertCell accept one parameter. And this parameter is the point at which to "insert" the new row/cell. Since J&#097;v&#097;script starts at 0, putting "0" would insert a row/cell before the first row/cell in the table/row. It's also possible to use negative numbers. Negative numbers actually count backwards from the end of the table. But, since 0 is already taken, they start counting at -1. -1 would insert a row/cell at the end of the parent. -2 would make it second to last. etc.<br />
<br />
Now, let's move on to an example.<br />
<pre class='prettyprint'><table border="1" id="thetable">
<tr><td>R1, C1</td><td>R1, C2</td></tr>
<tr><td>R2, C1</td><td>R2, C2</td></tr>
</table></pre>Now, our goal is to insert a row into this table. Let's say, we want to make it the third row, and it'll have two cells. The first cell's innerHTML will be "R3, C1" and the second's will be "R3, C2". Now let's make the code to modify it. There's two ways to do this, so take a look at the two different ways. (They're in different code boxes.)<br />
<br />
<pre class='prettyprint'>var newRow = &#100;ocument.getElementById("thetable").insertRow(2); // Insert the third row
var newCell1 = newRow.insertCell(0); // Insert the first cell
newCell1.innerHTML = "R3, C1"; // First cell's innerHTML
var newCell2 = newRow.insertCell(1); // Insert the second cell
newCell2.innerHTML = "R3, C2"; // Second cell's innerHTML</pre>Here's method number two. This uses the rows and cells arrays and negative inserts. If you don't know what they are, they're basically arrays containing every TR that belongs to the table and every TD that belongs to a row.<br />
<br />
<pre class='prettyprint'>var tab = &#100;ocument.getElementById("thetable"); // Reference the table to save space
tab.insertRow(-1); // Insert the third row as the last row. No variable assigned because we don't reference it as so later
var newCell1 = tab.rows&#91;2&#93;.insertCell(-1); // Insert the first cell as the last cell
newCell1.innerHTML = "R3, C1"; // First cell's innerHTML
var newCell2 = tab.rows&#91;2&#93;.insertCell(-1); // Insert the second cell as the last cell
newCell2.innerHTML = "R3, C2"; // Second cell's innerHTML</pre>Either way works perfectly fine, its just your preference. Anyways, here's what the new HTML for the table would look similar to:<br />
<pre class='prettyprint'><table border="1" id="thetable">
<tr><td>R1, C1</td><td>R1, C2</td></tr>
<tr><td>R2, C1</td><td>R2, C2</td></tr>
<tr><td>R3, C1</td><td>R3, C2</td></tr>
</table></pre>Now, for a quick breakdown of how the first code works. I won't be giving a break down for the second, as its an alternate method. If you want a challenge, break it down yourself and tell yourself how it works. :)<br />
<br />
<pre class='prettyprint'>var newRow = &#100;ocument.getElementById("thetable").insertRow(2);</pre>This line creates the new row as the third row. What we do is we have assigned an ID to the table, so we grab the table via the ID. Then, we insert the new row via the insertRow method. We also assigned a variable reference point to this new row so we can call other methods upon it later. ;)<br />
<br />
<pre class='prettyprint'>var newCell1 = newRow.insertCell(0);</pre>Remember how we assigned the variable to that row? Well, we're calling it here. This line is using the row stored in "newRow" to insert a new first cell for it. We also assign that cell to the variable "newCell1" for later uses.<br />
<br />
<pre class='prettyprint'>newCell1.innerHTML = "R3, C1";</pre>Here's that variable. All we do here is add the innerHTML for newCell1. How fun. :P<br />
<br />
<pre class='prettyprint'>var newCell2 = newRow.insertCell(1);
newCell2.innerHTML = "R3, C2";</pre>This is almost the same thing as the last two sections. Except, this is for the second cell instead.<br />
<br />
Anyways, hopefully this tutorial helps some novices again. This is one of the most useful table functions I've found, and I use it quite a bit whenever I use DOM for codes or make profile editable codes. So, enjoy. :D]]></description>
		<pubDate>Tue, 03 Mar 2009 07:32:02 +0000</pubDate>
		<guid isPermaLink="false">3</guid>
		<creator>cddude229</creator>
		<category>4</category>
	</item>
	<item>
		<title>Arguments in JavaScript</title>
		<link>http://www.prowebforums.com/tutorials/article/7-arguments-in-javascript/</link>
		<description><![CDATA[(This is a rather old tutorial from 2005, but it still should cover things decently.)<br />
<br />
I expect you to know the following things before reading this tutorial.<br />
<br />
- Arrays and ".length"<br />
- if()<br />
- for()<br />
- functions<br />
<br />
That should be all you NEED to know, but an extensive knowledge can always help.<br />
<br />
Now that that is out of the way, I'm gonna explain to you this code.<br />
<pre class='prettyprint'><script>
function writeThis (){
if(arguments.length > 0){
for(a=0;a<arguments.length;a++){
&#100;ocument.write(arguments&#91;a&#93;);
}
}
}


writeThis("Dude ","I Hate"," You :D");
</script></pre>And then I'll explain why its better then this one.<br />
<br />
<pre class='prettyprint'>
<script>
function writeThis (ext1,ext2,ext3){
&#100;ocument.write(ext1+ext2+ext3);
}


writeThis("Dude ","I Hate"," You :D");
</script></pre>Now first off, we have the standard opening line. Go ahead and ignore that and the ending line for now.<br />
<br />
The next line is the line creating the function, called writeThis. Now, if you look where there is normally the list of parameters (arguments), there are none. You may be thinking, "What? Why are there no parameters if they call parameters later?"<br />
<br />
First off, the answer to that is this. There are no parameters defined, because I'm teaching you a different way.<br />
<br />
Now, we go to the next line. Its an if() statement, containing "arguments.length > 0" Well, here's where the knowledge of arrays come in. You should know,t hat ".length" is used to say how many different levels there are in an array. Now, that means "arguments" is an array.... but for what?<br />
<br />
Its an array containing all parameters set to the function. So, basically, it contains all parameters listed. Now, onto its point. It currently is saying that there are parameters, cause its greater then 0.<br />
<br />
Now, onto the next line. Its just a for() loop, and it goes through the loop of the arguments.<br />
<br />
The next line just writes what the parameter actually is, and then after that we have the 3 ending brackets. Last two lines contain the calling function, and then the final calls the script end tag.<br />
<br />
Now, we'll compare it to the other code. The other code, is extremely simple, and shorter. But less efficient. Say you wanted to add more parameters to the code. Well, the first one would work fine, but the second one would mess up and you'd have some problems.]]></description>
		<pubDate>Tue, 03 Mar 2009 07:31:14 +0000</pubDate>
		<guid isPermaLink="false">7</guid>
		<creator>cddude229</creator>
		<category>4</category>
	</item>
</channel>
</rss>