We help IT Professionals succeed at work.

Why Doesn't the InputBox Show Up?

Martin Liss
Martin Liss asked
on
The following is some code that will be in an htm file that will be used to add functionality to IE's context menu. (The functionality is added via references to the file in the Registry). This one works except that the InputBox doesn't show up. What am I doing wrong?

<SCRIPT LANGUAGE = "VBScript">
Dim oWindow,oDocument,oSelect,oSelectRange,items,ptr,newtxt,bulletNum
Set oWindow = window.external.menuArguments
Set oSource = oWindow.event.srcElement 
Set oDocument = oWindow.document
Set oSelect = oDocument.selection

bulletNum = InputBox("Starting Value", "Title","1")
Set oSelectRange = oSelect.createRange()
If oSource.tagName = "TEXTAREA" Then
 items = split(oSelectRange.text,vbcrlf)
 For ptr = 0 to Ubound(items)
   items(ptr) = bulletNum & ".    "  & items(ptr)
 Next
 newtxt = join(items,vbcrlf)
 oSelectRange.text = newtxt
End If

Open in new window

Comment
Watch Question

Eric FlammOwner

Commented:
Loaded your script into a local html page, got the following error from IE9:
Object doesn't support this property or method: 'window.external.menuArguments'
Are you sure about this syntax? I've never tried to do exactly what you're doing. I commented out the 4 set statements and got the InputBox in IE9 (not working in Chrome,but VBScript may not be implemented in Chrome). I know that commenting the set statements out isn't a solution,but it shows there's nothing wrong with your InputBox statement - the script is just crashing before it gets there.
Martin Liss"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018

Author

Commented:
Yes that is valid syntax at least in all recent versions of IE through IE8.I don't have IE9 but if you wanted to you could test a similar script for an easier way to create a bulleted list by going to this article I wrote.

And actually the script doesn't crash but rather the InputBox statement is just ignored. The proof of that is that I will use it now on the following list

.    apple
.    pear
.    orange
.    lemon

If the script were working completely you would have seen
1.    apple
2.    pear
3.    orange
4.    lemon

The list started off as

apple
pear
orange
lemon

and the (now partial) bulleting happens after the InputBox.


Eric FlammOwner

Commented:
There is a comment here that security might be an issue with window.external. Can you try adding your site to Trusted Sites, or running IE as administrator, to see if that fixes the problem?
Martin Liss"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018

Author

Commented:
That comment was from 2008 and I don't know why there was a problem and I don't know if it was fixed but all I can tell you is that I and a whole bunch of other people at VBForums use similar files with absolutely no problems. And as I said in my last post it does run, just not the InputBox part. If I were to remove the InputBox and set bulletNum to 1 it would run perfectly.
"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
I found a solution. Substituting bulletNum = Trim(oWindow.prompt("Starting Value","1")) for bulletNum = InputBox("Starting Value", "Title","1") works.



Martin Liss"There is still no cure for the common birthday." ~John Glenn
Most Valuable Expert 2017
Distinguished Expert 2018

Author

Commented:
Self-solved.