/    Sign up×
Community /Pin to ProfileBookmark

FF – fine, MSIE – error, Reason???

I have the following encoder/decoder program.

It runs perfectly in FF, but returns a yellow caution in IE at a location that doesn’t make sense to me! 😮

Can anyone spot what is failing when run in MSIE? ?

[code]
<HTML>
<HEAD>
<script type=”text/javascript”>
var original = ”;
original += ‘0aAbBcC1dDeEfF2gGhHiI3jJkKlL4mMnNoO5pPqQrR6sStTuU7vVwWxX8yYzZ9’;
var alpha = original.split(”);
var letters = original.split(”);

function next(x) { return ((x+1) % alpha.length); }

function encodeRing(flag,num,info) {
// start offset at KEY value (allows base-36 entries [0-9,a-zA-Z])
var i2 = 0;
for (var i = 0; i < parseInt(num,36); i++) { i2 = ((i2+1) % alpha.length); }
// formulate character replacements
for (var i=0; i<alpha.length; i++) { letters[i] = alpha[i2]; i2=next(i2); }
info = decodeRing(flag,letters,info);
return info;
}
function decodeRing(flag,all,info) {
var wt = ”;
var et = ”;
var wh = ”;
var temp = info.split(“”);
for (q=0; q<temp.length; q++) {
wt = temp[q];
if (flag == true) {
wh = alpha.indexOf(wt); // encode part
if (wh == -1) { et += wt; } else { et += all[wh]; }
} else {
wh = all.indexOf(wt); // decode part
if (wh == -1) { et += wt; } else { et += alpha[wh]; }
}
}
return et;
}
function LoopEncode(flag,vKey,vLoop) {
for (var l=0; l<parseInt(vLoop,16); l++) { // hexidecimal counts allowed
document.f1.ta1.value=encodeRing(flag,vKey,document.f1.ta1.value); }
}

// Sample application set-up and display
function TestText() {
var str = ‘Now is the time for all good men to comen’;
str += ‘to the aid of their country.nn’;
str += ‘The quick red fox jumps over the lazy brown dog.nn’;
str += ‘Whatever the mind of man can conceive and believe,n’;
str += ‘he can achievenn01 23 45 67 89’;
return str;
}

var Counter = 0;
var LoopCounter = 0;
function EncodeCount() {
document.getElementById(‘TA1’).value
= encodeRing(true,document.getElementById(‘TB1’).value,document.getElementById(‘TA1’).value);
Counter++;
document.getElementById(‘CodeCnt’).innerHTML = Counter.toString();
}
function DecodeCount() {
document.getElementById(‘TA1’).value
= encodeRing(false,document.getElementById(‘TB1’).value,document.getElementById(‘TA1’).value);
Counter–;
document.getElementById(‘CodeCnt’).innerHTML = Counter.toString();
}
function LoopEncodeCount() {
LoopEncode(true,document.getElementById(‘TB1’).value,document.getElementById(‘TB2’).value);
LoopCounter++;
document.getElementById(‘LoopCodeCnt’).innerHTML = LoopCounter.toString();
}
function LoopDecodeCount() {
LoopEncode(false,document.getElementById(‘TB1’).value,document.getElementById(‘TB2’).value);
LoopCounter–;
document.getElementById(‘LoopCodeCnt’).innerHTML = LoopCounter.toString();
}
</script>
</HEAD>
<BODY>
<center>
<form name=’f1′ onsubmit=”return false”>

<table border=”1″><tr><td>
<textarea id=’TA1′ name=’ta1′ cols=’60’ rows=’20’></textarea>
<p>
Key Value: <input type=”text” size=’8′ name=”tb1″ id=”TB1″ value=”Key”>
Loop Pass: <input type=”text” size=’8′ name=”tb2″ id=”TB2″ value=”f”>
<button onclick=”document.getElementById(‘TA1’).value=TestText()”>Test text</button>
<br>
<input type=”button” value=”Encode Message” onclick=”EncodeCount();return false”>
<span id=”CodeCnt”>0</span>
<input type=”button” value=”Decode Message” onclick=”DecodeCount();return false”>
<br>
<input type=”button” value=”Loop Encode Message” onClick=”LoopEncodeCount();return false”>
<span id=”LoopCodeCnt”>0</span>
<input type=”button” value=”Loop Decode Message” onClick=”LoopDecodeCount();return false”>
</td>
<tr>
</table>

</form>
</body>
</html>
[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@KorMay 30.2009 — Anyway, a string acts, from some points of view, as an array (has a [B]length[/B], for instance), thus split() is useless, most of the time.
Copy linkTweet thisAlerts:
@JMRKERauthorMay 30.2009 — Thank you both.

The 'indexOf' problem had not crossed my mind as being the problem

and IE was pointing to a different line as being the problem.

Changing from the 'split' command may simplify the logic a bit.

Thanks again.


?
×

Success!

Help @JMRKER spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...