Random Snippets

  • Home
  • Sequence analysis blog
  • About
  • Categories
    • javascript
    • mysql
    • php
  • Subscribe via RSS

How to find and access parent nodes via JavaScript

June 26th, 2008  |  by Knix  |  published in javascript

function findParentNode(parentName, childObj) {
var testObj = childObj.parentNode;
var count = 1;
while(testObj.getAttribute(’name’) != parentName) {
alert(’My name is ‘ + testObj.getAttribute(’name’) + ‘. Let\’s try moving up one level to see what we get.’);
[...]

How to create your own customized calculator via JavaScript

April 26th, 2008  |  by Knix  |  published in javascript

function calculate(equation) {
var answer = eval(equation);
document.getElementById(’screen’).value = answer;
}
function pushButton(buttonValue) {
if (buttonValue == ‘C’) {
document.getElementById(’screen’).value = ”;
}
else {
[...]

How to validate email format via JavaScript

April 1st, 2008  |  by Knix  |  published in javascript

This JavaScript demo verifies that an email address is in the correct format and that the user has typed in the same address in both fields to prevent mistyping of the address. I have borrowed the regex for verifying the correct email format from a different site.

Demo

Email:

Please type in your email again:

How to dynamically remove/delete elements via JavaScript

March 26th, 2008  |  by Knix  |  published in javascript

function removeElement(parentDiv, childDiv){
if (childDiv == parentDiv) {
alert(”The parent div cannot be removed.”);
}
else if (document.getElementById(childDiv)) {
var [...]

How to find and replace text dynamically via JavaScript

March 7th, 2008  |  by Knix  |  published in javascript

This is a neat little script that demonstrates two things:
1) Find - If only the Find box is filled in, then the findMyText() JavaScript function will just perform a find for the div that is given. If there is a match, the text will be highlighted and marked in bold.
2) Find and Replace - [...]

Recent Posts

  • Sorting 2D associative arrays in PHP
  • About
  • Dynamic or on-the-fly percentage calculations with JavaScript
  • Sequence analysis blog
  • The dangers of embedding the notorious “void(0)” JavaScript code in the href attribute of the “a” tag

Recent Comments

  • drei on Simulate a button click via JavaScript
  • Subhee on How to count values with MySQL queries
  • Russell Day on How to hide, show, or toggle your div
  • phi on How to hide, show, or toggle your div
  • bornholy on How to hide, show, or toggle your div

Archives

Categories

  • javascript
  • mysql
  • php

Tag Cloud

add addition and subtraction calculator checkboxes checkEmail content demo demo content div id document getelementbyid dynamic Dynamically dynamic content emailRegEx find form getElementById html javascript input buttons input object input text javascript javascript code javascript demo javascript email javascript function javascript functions loop through menu multiplication mysql mysql query onClick onclick event query regex remove removeChild removeElement replace simulate styling valid email address verification verifyEmail


©2010 Random Snippets