Archive

Posts Tagged ‘JavaScript’

JavaScript Form Posting and Firefox

August 3, 2010 Leave a comment

While working on a .NET form today, I needed to add postback functionality to a Gridview control, using standard HTML radio buttons instead of traditional buttons (I had to confirm that a value was selected and if so, highlight the row).

So I assembled a prototype that implemented two hidden input fields. One held the radio group ID, and the other held the RowIndex value for the Gridviewrow; I needed these two pieces of information in order to flag the button as ‘checked’ as well as color the correct row.

So I whipped up a simple script:

function setPBItem(formItem, rowVal)
{
form1.hdnPBItem.value = formItem;
form1.hdnPBRowValue.value = rowVal;
form1.submit();
}

Works fine in IE 7, as well as Google Chrome… but it did not work at all in Firefox.

A little digging around led me to a few posts where others complained about the same problem in Firefox – although this is sound DOM syntax, none of it worked in Firefox.

However, changing it to this got it working:

function setPBItem(formItem, rowVal)
{
document.forms["form1"].hdnPBItem.value = formItem;
document.forms["form1"].hdnPBRowValue.value = rowVal;
document.forms["form1"].submit();
}

The difference here is simply adding the fully qualified DOM syntax. But apparently you also have to specify the form’s name; the index did not work in Firefox either.

Form submits just fine now. Something to keep in mind when implementing similar functionality.

Follow

Get every new post delivered to your Inbox.