0

I'm trying to generate HTML pages in an HTA application using VBScript as the language.

I can't seem to set the element name attribute. This code all works except for the code that sets the name. I output the frmMenu.InnerHTML at the end.

set selectApp = document.createElement("select")
selectApp.ID = "selApplication"
selectApp.name = "selApplication"
frmMenu.appendChild(selectApp)
Set selectApp.onchange = GetRef("Application_Change_Event")

I have used selectApp.Name = "selApplication" and that did not work either.

Here is the whole Sub()

GetRef("CycleMappingPage")
CycleMappingPage()

Sub CycleMappingPage()

    Set label1 = document.createElement("label")
    label1.innerHTML = "Application: "
    frmMenu.appendChild(label1)

    set selectApp = document.createElement("select")
    selectApp.ID = "selApplication"
    selectApp.name = "selApplication"
    frmMenu.appendChild(selectApp)
    Set selectApp.onchange = GetRef("Application_Change_Event")

    Set br1= document.createElement("br")
    frmMenu.appendChild(br1)

    Set br2 = document.createElement("br")
    frmMenu.appendChild(br2)

    Set label2 = document.createElement("label")
    label2.innerHTML = "Cycle: "
    frmMenu.appendChild(label2)

    Set selectCycle = document.createElement("select")
    selectCycle.setAttribute "name", "selCycle"
    frmMenu.appendChild(selectCycle)

    Set br3= document.createElement("br")
    frmMenu.appendChild(br3)

    Set br4 = document.createElement("br")
    frmMenu.appendChild(br4)

    Set inputButtonGenMap = document.createElement("input")
    inputButtonGenMap.setAttribute "type", "button"
    inputButtonGenMap.setAttribute "name", "btnRun"
    inputButtonGenMap.setAttribute "value", "Generate Map"
    frmMenu.appendChild(inputButtonGenMap)
    Set inputButtonGenMap.onclick = GetRef("GenerateMap")

    Set br5= document.createElement("br")
    frmMenu.appendChild(br5)

    Set br6 = document.createElement("br")
    frmMenu.appendChild(br6)

    Set inputButtonMainMenu = document.createElement("input")
    inputButtonMainMenu.setAttribute "type", "button"
    inputButtonMainMenu.setAttribute "name", "btnMainMenu"
    inputButtonMainMenu.setAttribute "value", "Main Menu"
    frmMenu.appendChild(inputButtonMainMenu)
    Set inputButtonMainMenu.onclick =  GetRef("LoadMainMenuPage")

    msgbox frmMenu.innerHTML

End Sub
DonkeyKong
  • 1,005
  • 14
  • 18
  • I believe that the answer is that the name attribute is not supported and the ID attribute should be used. – DonkeyKong Jul 10 '17 at 16:28
  • Form control and (i)frame elements do support name attribute. The question is not clear, how exactly the problem occurs? You can't see the name attribute of the select element in the message box which shows the inner HTML of `frmMenu`? – Teemu Jul 11 '17 at 05:44
  • that's right. And I can't use the name attribute to identify the element because it never associates. There are other problems, such as input boxes created using DOM are text by default but cannot be identified using the text property because it does not stick. HTA is old tech.... it's outdated and not well supported. Pretty disappointed that it's not better supported. – DonkeyKong Jul 11 '17 at 15:16
  • HTAs work as well as IE behind it, there shouldn't be any problems with HTML or DOM, at least nothing beyond the usual IE behavior. I'm not familiar with VBScript, hence I can't say if there's something wrong in your code. The DOM part looks OK, though. – Teemu Jul 11 '17 at 15:31
  • Btw. `input` element doesn't have `text` property (`option` has), `input` has `value` ... – Teemu Jul 11 '17 at 15:42
  • type=text?????? – DonkeyKong Jul 13 '17 at 02:32
  • ?? That's the value of `type` property ... – Teemu Jul 13 '17 at 04:00

1 Answers1

0

This is a behavior from old versions of IE (before IE8). You have two options to resolve it.

1) specify the name in the createElement call:

Set sel = document.createElement("<select name='hello'/>")

2) change your HTA's compatibility mode to at least IE 8 using the X-UA-Compatible header (see "X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE")


This behavior is documented under the name property:

In Internet Explorer 8 and later versions, you can set the name attribute at run time on elements that are dynamically created with the createElement method. To create an element with a name attribute in earlier versions of Windows Internet Explorer, include the attribute and its value when you use the createElement method.

Cheran Shunmugavel
  • 8,319
  • 1
  • 33
  • 40