user3707281 user3707281 - 6 days ago 6
HTML Question

How to output an function within HTML with vbscript

I have a html list which i want to dynamicly enable or disabled based on input. Usually at the end of the select you just use enabled or disabled to disable or enable the whole html list. But im not sure how to use function to do this.

<select size="5" name="name" onChange="rolevalue" enabler()>
<option value="1" selected="selected">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</p>
</select>


Here is my function

Function enabler()
if ListboxCustomer.value = 1 Then
document.write "enabled"
else
document.write "disabled"
end if
End Function


I know ListboxCustomer.value is set to 1 but the function isnt used. I know in C# i need to return my function for it to do anything, but ive read many examples of functions in vbscript and they dont use that. Any help? :)

Answer

If your doing this in a HTA use the following

<select size="5" name="name" onchange="enabler()">
    <option value="1" selected="selected">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>  
</select>

Then define your event handler

Sub enabler()
    Set List = window.event.srcElement
    List.Enabled = Not (List.Value = 1)
End Sub

For context this is purely a solution for the OPs specific context. I wouldn't recommend this approach normally. It's worth remember you can still use JavaScript in a HTA Application, but the OP specifically asked about using VBScript.

Comments