Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


VBScript equivelent of GetElementsByName("name")

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,47562
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBScript equivelent of GetElementsByName("name")
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 VBScript equivelent of GetElementsByName("name") - 5/24/2007 7:44:59 AM   
  bortiquai

 

Posts: 6
Score: 0
Joined: 5/24/2007
Status: offline
I need to use VBScript, but am having trouble getting the elements by name.

I need to know what the VBScript version of Document.GetElementsByName("name1") would be, or how to accomplish the same:

if i have:

<script>

objImg = document.GetElementsByName("images")

then i get an array that i can use like:

Img1Source = objImg[0].src

How would I accomplish this in VBScript?

Thanks
Matt
 
 
Post #: 1
 
 RE: VBScript equivelent of GetElementsByName("name... - 5/24/2007 7:48:29 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
I'm confused. What you posted is VBScript.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bortiquai)
 
 
Post #: 2
 
 RE: VBScript equivelent of GetElementsByName("name... - 5/24/2007 8:01:41 AM   
  ehvbs

 

Posts: 2223
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
No, it's Javascript.
Prove:  Img1Source = objImg[ 0 ].src
Try Img1Source = objImg( 0 ).src

< Message edited by ehvbs -- 5/24/2007 8:04:27 AM >

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: VBScript equivelent of GetElementsByName("name... - 5/24/2007 8:05:50 AM   
  bortiquai

 

Posts: 6
Score: 0
Joined: 5/24/2007
Status: offline
Hmm... Maybe it's my syntax then...

Here is an example of my code for what I am trying to do:

<head>
<title>My Page Title</title>
<script type="text/vbscript">
sub ChangePic()
   strElm = Document.GetElementsByName("Image1")
   msgBox(strElm[0].src)
end sub
</script>
</head>
<html>

<a onclick=ChangePic() href="vbscript:;"><img src="Coqui3.jpg" width="250" height="167" name="image1"></a>

</html>

So as you can see, when you click on the image, it should pop a Message Box that has the source ("Coqui3.jpg").

However, when i do this, i get a "Error on page" in my browser, and when i click to view the error, it says "Line 1, Char 1, Syntax Error, Code 0, Url: ThenTheFileName.html"

If I take out the part that says "Document.GetElementsByaName("image1") and replace it with a "String in quotes", then have it say msgBox(strElm), it runs fine.

What am i doing wrong? 

thanks
MATT

(in reply to bortiquai)
 
 
Post #: 4
 
 RE: VBScript equivelent of GetElementsByName("name... - 5/24/2007 8:05:53 AM   
  ebgreen


Posts: 5250
Score: 31
Joined: 7/12/2005
Status: offline
Ooops....Reading comprehension for the win.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 5
 
 RE: VBScript equivelent of GetElementsByName("name... - 5/24/2007 8:13:54 AM   
  ehvbs

 

Posts: 2223
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
This


      

works for me - () brackets, no ; after vbscript:

(of course the name strElm is really bad; should probably be oElm)

< Message edited by ehvbs -- 5/24/2007 8:15:22 AM >

(in reply to ebgreen)
 
 
Post #: 6
 
 RE: VBScript equivelent of GetElementsByName("name... - 5/24/2007 8:16:59 AM   
  bortiquai

 

Posts: 6
Score: 0
Joined: 5/24/2007
Status: offline
I chaanged the [0] to (0) but i get the same error....

(in reply to bortiquai)
 
 
Post #: 7
 
 RE: VBScript equivelent of GetElementsByName("name... - 5/24/2007 8:19:37 AM   
  bortiquai

 

Posts: 6
Score: 0
Joined: 5/24/2007
Status: offline
OK.  Got it now.  Thanks for your help

(in reply to bortiquai)
 
 
Post #: 8
 
 RE: VBScript equivelent of GetElementsByName("name... - 5/24/2007 8:32:29 AM   
  bortiquai

 

Posts: 6
Score: 0
Joined: 5/24/2007
Status: offline
Ok, well it works but I still have the "Error on Page" in my browser.
It actually works exactly as i want it to, but i just have to get rid of the stupid yellow error triangle... any ideas?

Thanks.

Here is all my code:

<Html>
<head>
<title>Untitled 1</title>
<script type="text/vbscript">
sub ChangePic(val)
set oElmA = Document.GetElementsByName("Image1")
set oElmB = Document.GetElementsByName("Image2")
set oElmC = Document.GetElementsByName("Image3")
set oHid = Document.GetElementsByName("hBig")
PicA = oElmA(0).src
PicB = oElmB(0).src
PicC = oElmC(0).src
if val = 0 then
oElmA(0).src = PicB
oElmB(0).src = PicA
oHid(0).href = PicB
elseIf val = 1 then
oelmA(0).src = PicC
oElmC(0).src = PicA
oHid(0).href = PicC
end if

end sub
</script>
</head>

<body>

<table style="width: 100%">
<tr>
 <td style="width: 328px"><img alt="" src="Coqui1.jpg" width="500" height="394" name="image1"></td>
</tr>
<tr>
               <td><a onclick=ChangePic(0) href="vbscript:;"><img src="Coqui2.jpg" width="250" height="167" name="image2"></a></td>
               <td><a onclick=ChangePic(1) href="vbscript:;"><img src="Coqui3.jpg" width="250" height="167" name="image3"></a></td>
</tr>
<tr>
 <td><a name="hBig" href="Coqui1.jpg" Targe="_Blank">Enlarge</td>
</tr>
</table>
</body>
</html>

(in reply to bortiquai)
 
 
Post #: 9
 
 RE: VBScript equivelent of GetElementsByName("name... - 5/24/2007 9:10:36 AM   
  ehvbs

 

Posts: 2223
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi bortiquai,

"vbscript:;" is a syntax error. You can use "vbscript:<SomeValidVBScriptCode>" to execute
code, but I'm not sure about the gory details. My advice: get rid of the "href= .." alltogether,
if you - as I assume - just want to call your ChangePic Sub.

Good luck!

ehvbs

(in reply to bortiquai)
 
 
Post #: 10
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> VBScript equivelent of GetElementsByName("name") Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts