Link to home
Start Free TrialLog in
Avatar of Martin Liss
Martin LissFlag for United States of America

asked on

Why Doesn't the InputBox Show Up?

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

Avatar of Eric Flamm
Eric Flamm
Flag of United States of America image

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.
Avatar of Martin Liss

ASKER

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.


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?
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.
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Self-solved.