Short script--only working in IE

I’ve been tasked with fixing a problem on a site that I didn’t develop, but in a nutshell somebody wrote a little Javascript that appears to only be working in IE. I’m not sure why…would anybody be kind enough to have a quick look?

Page in question is: http://www.thomastonauction.com/newAbsenteeSignature.php

The script not working is in the head of that page, and looks like this:

<!--this appears to be the script that is called when users click the "submit to thomaston auction" button,
which should trigger an email containing the bid info. to "auction@kajav.com" 
and open a printable copy of the bid in a new window ("newAbsenteePrintForm.php")-->

<script language="JavaScript" type="text/JavaScript">

 
function openPrintForm(sid) 
{ 
  var matchName = document.getElementById("matchName"); 
  var signature = document.getElementById("signature");
  
  if (matchName.value != signature.value)
  {
     alert("Signature input must match your name");
     return;
  }
  var url = "newAbsenteePrintForm.php?sid=" + sid;
  window.open(url ,"AbsenteeBidsPrintForm",
     "menubar=no,toolbar=no,directories=no,location=no,status=no,scrollbars=yes,resizable=yes");
}

</script>

Well, one thing I see is that they’re using getElementById to pick up an element that doesn’t have an ID.

<input type="hidden" name="matchName" value="">

If you give it an id

<input type="hidden" name="matchName" id="matchName" value="">

that might pick it up.

Another is that the inputs are in form with no name or ID.

I think you could also pick it up with

document.form1.matchName.value

if the form name was ‘form1’.

I’m hardly an expert and expect others will correct me, but I hope this helps.

Thanks for the suggestions. Neither one worked, unfortunately.

It definitely works in IE, but only in IE. What mistake is IE forgiving in the code that other browsers are not?

Where are you adding: “openPrintForm(sid)” in the web page?..To pass the “sid” value?

Internet Explorer pollutes the ID namespace with names. That’s why the getElementById is matching on the name in IE but failing to find the missing id in all other browsers.

sorry, I don’t follow your question. You mean “why?” instead of “where?”

It looks to me like the coder added the (sid) to pass some data to the “PrintForm” which then displays a sort of confirmation page.

OK, thanks…that makes sense. Let me go back and look again at the ID attributes in the form and see if I can get this to work. Will report back soon.

Appreciate all the help everyone.

BTW, when you say IE “pollutes the ID namespace with names,” can you explain more precisely what IE is doing in this particular case that allows the Javascript to execute properly?

You guys rock.

I assigned the ID=“signature” to the texfield in the form and “matchName” to the hidden field.

It works in everything I’ve tested now except Safari 1.2 (works fine in current version).

Given the tiny percentage of people using ancient Safari browsers, I’d say that’s good to go.

Man, I hate working on other people’s code…especially when it’s all cobbled together and not properly tested.

Why on earth would you only test a public site like this using IE?

I won’t tell you how many hours I spent troubleshooting this.

Thanks again.

Let’s say you have the following:

<input name=“a”>
<input name=“b” id=“b”>
<div id=“c”>

For all browsers except for IE the id namespace contains “b” and “c” because those are the only ids in that code. IE pollutes the namespace with name attributes as well as is and so for IE and only IE the id namespace also contains “a”. Therefore in IE you can use document.getElementById(‘a’) and get the forst of the input fields but in any other browser where “a” isn’t in the id namespace that call will return null.