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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to call a function from an <area href="#" Onclick... 1

Status
Not open for further replies.

uncleelwyn

Technical User
Nov 4, 2002
4
US
HI,

trying to do a neat little project, which is to have an imagemap, of the printers in our office.
when a user clicks on a printer, it will call a vbscript routine to add the printer and set it as the default.

the sub is :

<script LANGUAGE=&quot;VBScript&quot;>
sub printer1()
Set WshNetwork = CreateObject(&quot;WScript.Network&quot;)
PrinterPath = &quot;\\sydney\printer1&quot; PrinterDriver = &quot;Lexmark Optra S PS&quot;
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
WshNetwork.SetDefaultPrinter &quot;\\printerver.ourcompany.net\printer1&quot;
msgbox &quot;Your Printer Has been set to printer1&quot;
end sub
</script>

and in the body I call it through :
<map name=&quot;FPMAP0&quot;)
...
<area HREF=&quot;#&quot; OnClick=printer1() shape=&quot;rect&quot; coords=&quot;794, 213, 868, 246&quot;>
</map>
...


what I'd like to do is instead of having a seperate sub for each printer, I'd like to pass the name of the printer to the routine, because I have a large amount of printers in the office.
Any ideas how I pass the printername into the sub?

Cheers.
 
Do this :
Code:
<script LANGUAGE=&quot;VBScript&quot;>
sub printer(mapObject)
    printername=mapObject.id
    Set WshNetwork = CreateObject(&quot;WScript.Network&quot;)
    PrinterPath = &quot;\\sydney\&quot; & printername
    PrinterDriver = &quot;Lexmark Optra S PS&quot; 
    WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
    WshNetwork.SetDefaultPrinter &quot;\\printerver.ourcompany.net\&quot; & printername 
    msgbox &quot;Your Printer Has been set to &quot; & printername
end sub
</script>

and in the body I call it through :
<map name=&quot;FPMAP0&quot;)
...
<area id=&quot;printer1&quot; HREF=&quot;#&quot; OnClick=printer(this) shape=&quot;rect&quot; coords=&quot;794, 213, 868, 246&quot;>
</map>
...

Tell me if it works ('this' keyword works well under JS but I'm not sure under VBS). Water is not bad as long as it stays out human body ;-)
 
Targol,

thanks for the suggestion. Unfortunately, It doesn't seem to call the sub at all now. I'm wondering whether what I am attempting is possible at all?

I've seen the knowledgebase article on adding printers, but using forms or buttons to call the routine, but I haven't been able to find any examples of passing a string into a sub/function from a <AREA> or <A> tag????
 
Targol...

thankyou, thankyou...

it did actually work -

what I'd done was instead of having

<area id=&quot;printer1&quot; href=&quot;#&quot; OnClick=printer(this)

I actually put
OnClick=printer(Object)

because I thought that the word in the parenthese after OnClick=printer should be the same as in
sub printer (mapObject)

which was wrong....

so is using the word &quot;this&quot; a standard thing?
 
&quot;This&quot; is a reserved keyword that points to the currently selected object (in the case, the object throwing the event). Water is not bad as long as it stays out human body ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top