I’m using JavaScript to submit a form that I make from scratch. The code below works in Chrome, but not in Firefox or IE. How can I make and submit a form and have it work across ‘all’ browsers?
function someFunction(){
var SomeForm = document.createElement("form");
addInputFieldToForm("SpecialName_SortField","UpdateDate",SomeForm);
addInputFieldToForm("SpecialName_SortOrder","false",SomeForm);
addInputFieldToForm("Operation","Search",SomeForm);
SomeForm.action = "<%=link("direct", "WorkspaceDisplay") %>"; // assume this URL is valid (it is).
SomeForm.method = "post";
SomeForm.target = "_top";
SomeForm.submit();
}
//EDIT: Added this function to the question just so there's less mystery (not because it matters, really)
function addInputFieldToForm(elementName, elementValue, theForm) {
var inputElement = document.createElement("input");
inputElement.name = elementName;
inputElement.value = elementValue;
inputElement.id = elementName;
theForm.appendChild(inputElement);
}
You have to append the form to the document before it can be submitted.
If you don’t want to change the UI, you can apply a style to the form.
Side note: You’re using
SomeFormas a variable name. It’s a perfectly valid JavaScript variable, but agaist the conventions. Camel-cased variables should only be used to name constructors, e.g.Array,Object,MyClass.