msie 6, 7 fails to pass form field value to function, how fix?

G

Grant

Hi there,

I've been away from javascript for years, forgive me if this is an FAQ ;)

The following fragment works fine in Firefox, Opera and Safari
(on WinXP), but fails with msie7 on WinXP and msie6 on Win98.

See where I've put an alert() to catch the msie problem of an
undefined value. For context, see: http://bugsplatter.mine.nu/ip2c/
To trigger the problem, check one of the 'preview these examples'
checkboxes then click the [Preview] button.

Seeking ideas on how to fix this, I've read the FAQ and tried the
alternate form field value access method from the FAQ to no avail.

I'm not using browser detection, and like to avoid it.
....
function filterPreview(obj, s, e) {
if (s == " " || s.length == 0) {
obj.write('[empty]');
return;
}
var c; var re = new RegExp('[`~$^*?]');
for (var i = 0; i < s.length; i++) {
if (!s) {
alert('msie is busted, try Firefox, Opera or Safari!');
return;
}
if (s == '\\') {
c = s[++i];
if (e && c == '\\') { obj.write('\\'); }
if (e && c == 'n') { obj.write('\n'); }
if (e && c == 't') { obj.write('\t'); }
}
else if (!re.test(s)) {
obj.write(s);
}
}
}
var previewWindow = null;
var previewActive = 0;
function popupPreviewWin(obj) {
++previewActive;
previewWindow = window.open('','preview',
'height=200,width=780,menubar=0,toolbar=0,' +
'status=0,scrollbars=1,resizable=1,addressbar=0');
var pw = previewWindow.document;
pw.write('<html><head><title>cc2block preview<\/title>' +
'<\/head><body bgcolor="#d7e7fc"><pre>');
pw.write('# [header]');
if (obj.comment.value.length > 0) {
filterPreview(pw, '\n# \n# ' + obj.comment.value, false);
}
pw.write('\n#\n');
filterPreview(pw, obj.prefix.value + ' ', true);
pw.write('xxx.xxx.xxx.xxx-yyy.yyy.yyy.yyy');
filterPreview(pw, ' ' + obj.postfix.value, true);
if (obj.postdup.checked) {
pw.write('\n');
filterPreview(pw, obj.prefix.value + ' ', true);
pw.write('xxx.xxx.xxx.xxx-yyy.yyy.yyy.yyy');
filterPreview(pw, ' ' + obj.postfx2.value, true);
}
pw.write('\n...');
if (obj.summary.checked) {
pw.write('\n# match: ?, merge: ?, list: ?, ?.???%');
}
else {
pw.write('\n# end');
}
pw.write('\n<\/pre><\/body><\/html>');
pw.close();
previewWindow.focus();
}
function closePreview() {
if (previewActive > 0) {
previewActive = 0
previewWindow.window.close();
}
}

Thanks,
Grant.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top