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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forefox issue with document.createElement()?

Status
Not open for further replies.

jrenae

Programmer
Jan 18, 2006
142
US
Hello,

I'm new to having to code to firefox, and I'm finding that I get a javascript error in firefox that I don't get in IE. The line that errors is:
Code:
var dependentOn = document.createElement("<INPUT TYPE=\"hidden\" name=\"" + dependentOnId + "\" id=\"" + dependentOnId + "\" value=\"" +  arDependentOn[i] + "\"/>");

The error I'm getting is:
Error: [Exception... "String contains an invalid character" code: "5" nsresult: "0x80530005 (NS_ERROR_DOM_INVALID_CHARACTER_ERR)" location: "http:....Line: 646"]
Source File: http:....
Line: 646

is the syntax I'm using for creating my hidden field not acceptable for firefox?
 
Specifying properties like that is IE-only, as far as I know. For creating pre-typed inputs cross-browser, I've used this code before:

Code:
function createInput(inputName, inputType, inputValue) {
	if (typeof VBArray != "undefined") {
		var input = document.createElement("<input type=\"" + inputType + "\" name=\"" + inputName + "\" value=\"\">");
		input.value = inputValue;
	} else {
		var input = document.createElement("input");
		input.type = inputType;
		input.name = inputName;
		input.value = inputValue;
	}
	return input;
}

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top