Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Central

getElementByName on other websites

Author Message
andrethegiant



Joined: 08 May 2005
Posts: 78

Posted: Sat Jul 23, 2005 - 6:49 pm    Post subject: getElementByName on other websites Reply with quote

I'm trying to get the value of something on another website. I'm using
var x = document.getElementsByName("hR1")[0].value

document.getElementById("main").innerHTML = x

but this obviously doesn't work because I know I need to insert the url of the site I want to get it from, but I don't know where to do that. Any help would be appreciated.
View user's profile Send private message Send e-mail Widgets
gnome
Administrator


Joined: 26 Sep 2004
Posts: 145

Posted: Sun Jul 24, 2005 - 12:19 am    Post subject: Reply with quote

Not so easy. You'll need to use XmlHttpRequest and crawl the DOM that way.
View user's profile Send private message Widgets
andrethegiant



Joined: 08 May 2005
Posts: 78

Posted: Sun Jul 24, 2005 - 12:24 am    Post subject: Reply with quote

Ok. I have this, which I used before, but it didn't work. It seems right to me. What am I doing wrong?

Code:

req = new XMLHttpRequest()
   req.open("GET", "http://www.site.com", false)
   req.send(null);
   results = req.responseText

x = results.getElementsByName('info')[0].value
   
 document.getElementById('main').innerHTML = x;
View user's profile Send private message Send e-mail Widgets
gnome
Administrator


Joined: 26 Sep 2004
Posts: 145

Posted: Sun Jul 24, 2005 - 1:34 am    Post subject: Reply with quote

See my response in this thread:

http://www.dashboardwidgets.com/forums/viewtopic.php?p=4634#4634

Also, the method is getElementsByTagName, and it's likely that you mean to use the properties .innerText or .innerHtml rather than .value.
View user's profile Send private message Widgets
andrethegiant



Joined: 08 May 2005
Posts: 78

Posted: Sun Jul 24, 2005 - 2:29 am    Post subject: Reply with quote

hmmm, that didn't work. I'm sure it's value because i'm trying to get something from a hidden input.

I can also do the same thing I'm trying to do with variables in regular expression. is it possible to insert variables in a reg exp string? ex:

Code:
reg = /name="hR"+x+"" value="[\d]+/gi


where x is the variable, an interger. so the expression would find matching strings for hR0, hR1, hR2, etc. i know this doesn't work, but does anyone know the correct syntax?
View user's profile Send private message Send e-mail Widgets
Chris



Joined: 27 Jan 2005
Posts: 344
Location: Durham, UK

Posted: Sun Jul 24, 2005 - 4:47 am    Post subject: Reply with quote

andrethegiant wrote:
hmmm, that didn't work. I'm sure it's value because i'm trying to get something from a hidden input.

I can also do the same thing I'm trying to do with variables in regular expression. is it possible to insert variables in a reg exp string? ex:

Code:
reg = /name="hR"+x+"" value="[\d]+/gi


where x is the variable, an interger. so the expression would find matching strings for hR0, hR1, hR2, etc. i know this doesn't work, but does anyone know the correct syntax?


Well, the first problem is that you're using getElementsByTagName on a string (responseText) rather than a node list like it needs (responseXML).

Working with HTML returned can be a bit of a hassle, so your regular expressions on the responseText method is probably the best way to go. If you want to build it up, inserting your variable, try doing it like:

var reg = new RegExp("name=\"hr\"" + x + "\" value=\"[\d]+", "ig");

(I haven't tested that, so apologies if it's not quite right).
View user's profile Send private message Send e-mail Visit poster's website AIM Address Widgets
andrethegiant



Joined: 08 May 2005
Posts: 78

Posted: Sun Jul 24, 2005 - 5:51 am    Post subject: Reply with quote

Thank you! I finally got it. It didn't work for a while, but then I remembered that the backslashes had to be escaped because it is a literal string. so it would be

....value=\"[\\d]+"......

Thanks again!
View user's profile Send private message Send e-mail Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group