Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document.form.action unsupported in Internet Explorer

Status
Not open for further replies.

SetoKaiba

Programmer
Jun 16, 2004
28
US
Hello, my script is rather simple:

function preview_post() {
document.postform.action = 'submain.php';
document.postform.d.value = 'preview';
w = window.open('submain.php?d=preview','previewwin','scrollbars=yes,width=500,height=600');w.focus();
document.postform.target = 'previewwin';
document.postform.submit();
}

The HTML snippets relevent to this:
<form method="post" action="" enctype="multipart/form-data" name="postform">
<input type="button" onClick="preview_post();" value="Preview Message Body" style="width:35%;"></input>

The function works correctly in Firefox 2, the window is popped open, and form executed to that window.
However in IE, the function craps out at:
document.postform.action = 'submain.php';
(I commented out the rest of the function except that to check. It does not cough out an error with the line afterwards, referring to a form field).

The error is:
Object does not support this property or method.

This leads me to believe that IE recognizes the object, but it doesn't want to change the action field of it.

Is the way I did it above not considered the "Standard" way? I tried using document.forms["postform"] however the same error arises.

(The script needs to work in Firefox and IE)
 
Have you used document's associative array to access the form itself?
Code:
document.forms['postform'].action = 'submain.php';

Lee
 
probably simplest to get in the habit of using only IDs for forms and not names. A NAME attribute on a form is not XHTML Strict compliant. Then just use the


document.getElementById("formId") statement to grab your form.

<.
 
I changed the code accordingly and received the same error.

New code for "preview_post()":

function preview_post() {
document.forms['postform'].action = 'submain.php';
document.forms['postform'].d.value = 'preview';
w = window.open('submain.php?d=preview','previewwin','scrollbars=yes,width=500,height=600');w.focus();
document.forms['postform'].target = 'previewwin';
document.forms['postform'].submit();
}

-----
On a sidenote, I tested it in Mozilla again and it worked. Is this the DOM Standard for referring to form stuff, as it'd be a good idea to convert everything to the DOM Standard anyway. However, the problem with IE7 still remains.
 
Hate to double post, but I can't see an edit link on my own above.
I changed the function again based on monksnake's suggestion:

function preview_post() {
document.getElementById("postform").action = 'submain.php';
document.getElementById("postform").d.value = 'preview';
w = window.open('submain.php?d=preview','previewwin','scrollbars=yes,width=500,height=600');w.focus();
document.getElementById("postform").target = 'previewwin';
document.getElementById("postform").submit();
}

The problem still remains in IE. I assume the function, however, is completely XHTML Strict compliant? (I'll check some XHTML Strict information sites afterwards)
 
Ironic, I might have the same problem as him then. I'll have to go off and change my hidden "action" variable which controls 100% of my site to usraction or something because poor little IE can't tell the difference between a form element and a form field based on syntax.

Thanks for finding that, you beat me with the better Google search.
 
With Javascript, if you have 2 objects with the same name, you have a 50/50 chance of the scripting engine choosing the wrong one. It sounds like IE is written to choose elements over attributes, where Firefox chooses attributes first. If you'd tried to access the action hidden input with Javascript in FF, you wouldn't have been able to.

Naming subelements the same as attributes or attribute values is looking for trouble, as you just experienced.

Lee
 
If you'd tried to access the action hidden input with Javascript in FF, you wouldn't have been able to.

Unless you use the elements collection (which you should be specifically to avoid these kinds of problems)

Naming subelements the same as attributes or attribute values is looking for trouble, as you just experienced.

Lee hit the nail right on the head with that statement. You really shouldn't be using names like action, method, submit, etc.. for your element names.

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 
I should have been more clear. I meant if SetoKaiba had tried to access the hidden input using the same syntax as he did in his original post in Firefox, he'd have had problems.

Lee
 
Ahh, I couldn't help taking a shot at M$.
Anyway, the thing worked, and I'll keep the suggestion in mind. It surprises me that the Error Console didn't pop a warning about having the same names, it's been pretty helpful in getting those bugs.
Appreciate all the help guys.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top