phasejump
09-04-2010, 12:23 AM
<script language="JavaScript"><!--
function insertNthChar(string,chr,nth) {
var string = document.getElementById('mycoupon').innerHTML;
var output = '';
for (var i=0; i<string.length; i++) {
if (i>0 && i%4 == 0)
output += chr;
output += string.charAt(i);
}
return output;
}
//--></script>
<body onLoad="alert(insertNthChar('', '-', 4));">
The current code works perfectly with a pop up alert, but I want it to target an ID instead. The ID is 'mycoupon'. Does anyone know how to do this?
function insertNthChar(string,chr,nth) {
var string = document.getElementById('mycoupon').innerHTML;
var output = '';
for (var i=0; i<string.length; i++) {
if (i>0 && i%4 == 0)
output += chr;
output += string.charAt(i);
}
return output;
}
//--></script>
<body onLoad="alert(insertNthChar('', '-', 4));">
The current code works perfectly with a pop up alert, but I want it to target an ID instead. The ID is 'mycoupon'. Does anyone know how to do this?