Results 1 to 7 of 7

Thread: Can I access the data value of the object tag via javascript?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    35

    Can I access the data value of the object tag via javascript?

    the subject says it all
    thanks in advance,
    Michael

  2. #2
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Yes you can, but what do you mean by "object" tag?

    I may be thinking of DOM3 (which isn't standard, yet), but you can access the value of anything with getElementByID, getAttribute, getChild, and stuff like that.

    Good places to start is post and example of what you are trying to do, or check out developer.netscape.com, or www.w3c.org.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    35
    Originally posted by CiberTHuG
    Yes you can, but what do you mean by "object" tag?
    what i mean by the object tag is like this
    Code:
    <OBJECT ID="CantFindThisElement" DATA="blah.html" TYPE="text/html" WIDTH=300 HEIGHT=300>
    </OBJECT>
    I have been trying, and you're probably going to yell at me...
    Code:
    document.all.CantFindThisElement.data.value
    and variants of that but havent found anything that will work.
    Thanks
    Michael

  4. #4
    Black Cat JoshT's Avatar
    Join Date
    Nov 2000
    Location
    WNY, USA
    Posts
    4,032
    This works for IE6 and Mozilla 0.9.9:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    	"http://www.w3.org/TR/html4/loose.dtd">
    			
    <html lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    	<title>Untitled</title>
    <script type="text/javascript">
    function testf() {
    	var vo = document.getElementById("CantFindThisElement");
    	alert(vo.data);
    	vo.data = "http://www.google.com/";
    	alert(vo.data);
    }
    </script>
    </head>
    
    <body>
    <OBJECT ID="CantFindThisElement" DATA="blah.html" TYPE="text/html" WIDTH=300 HEIGHT=300>
    </OBJECT>
    <span onclick="testf();">CLICK</span>
    
    </body>
    </html>
    Josh
    Get these: Mozilla Opera OpenBSD
    I have books for sale: "MCSD in a Nutshell" and "VB Distributed Exam Cram" - PM me for details. Will also trade for a decent ATX Pentium 2 MB/CPU/RAM combo.

  5. #5

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    35
    thanks
    michael

  6. #6
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    Yes, I should yell at you because there is no document.all.

    But as Josh showed, document.getElementById works. If you look at www.w3c.org/DOM you can look at the DOM 2 recommendations and find something that may work in IE 5.x or other older browsers.
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  7. #7

    Thread Starter
    Member
    Join Date
    Jan 2002
    Posts
    35
    I had the object in a 'form' so thats why i had document.all (but ASP/VB is my forté javascript/DOM is a bit new for me)
    thanks again,
    Michael

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width