| Subcribe via RSS

stopPropagation() and cancelBubble

May 14th, 2008 | No Comments | Posted in javascript by dreamluverz


Another way of doing the cancelBubble:

function dropButtonClick(e) { if( typeof( e ) == "undefined" && typeof( window.event ) != "undefined" ) e = window.event; // do things.... if (typeof( window.event ) != "undefined" ) { // IE e.cancelBubble=true; } else { // Firefox e.stopPropagation(); } }

source: http://blogs.charteris.com/blogs/edwardw/default.aspx

Tags: , ,

cancelBubble

May 14th, 2008 | No Comments | Posted in javascript by dreamluverz

I have this function but something was wrong with firefox. I got undefine value. After taking a closer look in my code I forgot to pass the 'event' parameter on my function.



function dps_cancel_bubble(e)
{
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
}

so you need to call it like this.

<img src=”" onlickc=”dps_cancel_bubble(event)”> DONT EVER FORGET TO PASS event or else you’ll get crazy looking for the bug :P I almost did :lol:

Tags: , , , , , ,

array push in javascript

May 14th, 2008 | No Comments | Posted in javascript by dreamluverz

Example:

for(d = 0; d< arr.length; d++){
arr2[arr2.length++] = arr[d];
}

source: http://blog.dreamvib.com/programming/javascript-array_push/

Tags: ,

javascript: typeof

March 8th, 2008 | No Comments | Posted in javascript by dreamluverz

typeof returns one of the following strings:

  • number
  • string
  • boolean
  • object
  • function
  • undefined

typeof(typeof(x)) is always string, no matter what x actually is.

IE seems to think that some functions are objects rather than functions: typeof(document.getElementById) returns object.

 

source: http://www.adp-gmbh.ch/web/js/operators/typeof.html

Tags: ,

insertRow() - inserting dynamic rows in javascript

February 13th, 2008 | No Comments | Posted in javascript by dreamluverz

Summary

insertRow inserts a new row in the table.

Syntax

var row = HTMLTableElement.insertRow(index);
  • HTMLTableElement is a reference to a HTML table element.
  • index is the row index of the new row.
  • row is assigned a reference to the new row.
    If index is -1 or equal to the number of rows, the row is appended as the last row. If index is omitted or greater than the number of rows, an error will result.

Example

<table id="TableA">
  <tr>
    <td>Old top row</td>
  </tr>
</table>

<script type="text/javascript">

  function addRow(tableID)
  {

    // Get a reference to the table
    var tableRef = document.getElementById(tableID);

    // Insert a row in the table at row index 0
    var newRow   = tableRef.insertRow(0);

    // Insert a cell in the row at index 0
    var newCell  = newRow.insertCell(0);

    // Append a text node to the cell
    var newText  = document.createTextNode('New top row')
    newCell.appendChild(newText);
  }

// Call addRow() with the ID of a table
addRow('TableA');

</script>
source: http://developer.mozilla.org/en/docs/DOM:table.insertRow
Tags: , ,

checkbox select all function

February 7th, 2008 | 1 Comment | Posted in javascript by dreamluverz

I created some function for selectall checkbox. It works coz i’ve been using this.

obj_chkall - is the object of the checkbox that when you click will check all other checkboxes usually on mails
chkbox_name - is the name of the field of the checkboxes

function dps_chkall(obj_chkall, chkbox_name){
var form_name = obj_chkall.form;

if(typeof(chkbox_name) == 'object'){
obj_chkall.checked = false;
}else{
for(var d = 0; d < form_name.elements.length; d++){
if(form_name.elements[d].name == chkbox_name){
form_name.elements[d].checked = obj_chkall.checked;
}
}
}
}

Tags: , ,