403e57e2be130d2218f992b86dfa8260

I found this great piece of code from an ad server and thought to myself that I should learn to make my own JS legacy compliant. Can anyone please tell me if they know a better way to do this? Thanks in advance.

document.write ('<noscript>\n');
document.write (imageClick);
document.write ("</noscript>");

Refactorings

No refactoring yet !

D41d8cd98f00b204e9800998ecf8427e

Andre Steenveld

October 31, 2007, October 31, 2007 07:42, permalink

No rating. Login to rate!

lol, how about not using document.write()? Since doing a write action on document is a javascript function by it self. Are you sure it wasn't a piece of serverside javascript though?

D41d8cd98f00b204e9800998ecf8427e

Robb

October 31, 2007, October 31, 2007 14:24, permalink

1 rating. Login to rate!
//Globale Variable

var Leerstring = " ist leer. Bitte geben Sie hier einen Wert ein."



function ueberpruefeForm(form) {

	return 	(pruefeString(form.Vorname, "Vorname") &&

				 pruefeString(form.Name, "Name") &&	

				 pruefeString(form.Strasse, "Strasse") &&

				 pruefeString(form.Hausnummer, "Hausnummer") &&

				 pruefeString(form.PLZ, "Postleitzahl") &&

				 pruefeString(form.Ort, "Ort") &&

				 pruefeEmail(form.Email, "E-Mail"))

}





function KontrolleNull(eingabe) {

	if ( eingabe.length == 0 ) {

   	return false

	}

	else {

 	return NurSpace(eingabe)

	}

}



function NurSpace(eingabe) {

	for ( var i=0; i<eingabe.length; i++ ) {

   	if ( eingabe.charAt(i) != " " ) {

	   	return true

		}

	}

	return false

}



function zaehleZeichen(eingabe, anz) {

	if ( eingabe.length == anz ) {

		return true

	}

	else {

		return false  

	}

}



function istZahl(eingabe) {

	for ( var i=0; i<eingabe.length; i++ ) {

		aktZeichen = eingabe.charAt(i)

		if ( aktZeichen < "0" || aktZeichen > "9" ) {

			return false

		}

	}

	return true

}



function ZahlinBereich(eingabe, unten, oben) {

	var zahl = parseInt(eingabe);

	return ((zahl >= unten) && (zahl <= oben))

}



function pruefeString(eingabe, str) {

	if ( KontrolleNull(eingabe.value) && NurSpace(eingabe.value)) {

		return true

	}	

	else {

		eingabe.focus()

		alert("Das Feld " + str + Leerstring)

		return false

	}

}



function pruefePLZ(eingabe) {

	if ( istZahl(eingabe.value) && zaehleZeichen(eingabe.value, 5) && ZahlinBereich(eingabe.value, 01000, 99999) ) {

		return true

	}	

	else {

		eingabe.focus()

		alert("Ungültige PLZ - bitte überprüfen Sie Ihre Eingabe")

		return false

	}

}



function pruefeEmail(address) {

	email = address.value;

	format = /^(.+)@(.+)\.(.{2,3})/;

	format.exec(email);

	if (!(RegExp.$1 && RegExp.$2 && RegExp.$3)) {

		alert("Keine gültige E-Mail-Adresse!");

		address.focus();

		return false;

	}
403e57e2be130d2218f992b86dfa8260

Gary Haran

October 31, 2007, October 31, 2007 14:59, permalink

No rating. Login to rate!

No sir. This was client side JS sent to us via an ad server. The entirity of their code is like that. They declare a variable and set a value to it and the next line they redeclare it with a different value. Everything about their ad server is random and it boggled my mind so much I thought I'd share.

Your refactoring





Format Copy from initial code

or Cancel