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!

createElement('SELECT') not working

Status
Not open for further replies.

snakehips2000

Programmer
Nov 10, 2003
95
GB
Maybe I'm missing something in how this javascript statement is meant to work but I can't get a (blank) select box to display when I load a page. Any advice appreciated:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
function makeForm() {
objSel=document.createElement('SELECT');
}
</script>
</head>
<body onLoad="makeForm();">
</body>
</html>
 
Hi

[ol]
[li]That code works correctly[/li]
[li]There is no reason for the [tt]select[/tt] to appear[/li]
[/ol]
JavaScript:
        [b]function[/b] [COLOR=darkgoldenrod]makeForm[/color][teal]()[/teal] [teal]{[/teal]
            objSel[teal]=[/teal]document[teal].[/teal][COLOR=darkgoldenrod]createElement[/color][teal]([/teal][green][i]'SELECT'[/i][/green][teal]);[/teal]
            [highlight]document[teal].[/teal]body[teal].[/teal][COLOR=darkgoldenrod]appendChild[/color][teal]([/teal]objSel[teal]);[/teal][/highlight]
        [teal]}[/teal]
Note that the above is just a quick & dirty example. You should place [tt]form[/tt] elements only inside [tt]form[/tt] tags.

Feherke.
 
Much appreciated. I guess I didn't word the aim of the exercise too well - I needed to know how to make the SELECT box visible. Your example answerered this, thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top