SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot DrkFusion's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    whats wrong with this two line script?

    Code:
    		var objectOne = document.getElementById( object1 );
      		document.testForm.testVar.value = objectOne.style.top;
    Code:
    <div id="object1" style="left: 50px; top: 150px; width: 250px; height: 120px; text-align: center" >OBJECT 1</div>
    Code:
    <form name="testForm" action="simple.html" method="GET">
     	<input type="hidden" name="testVar">
     	<input type="submit" value="submit">
     </form>

    I am new to javascript. Please tell me why I am not geting a value.
    ZunePoint.com
    Yes, we cover everything and anything zune.

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No quotation marks around the string argument in the first function call.
    Code:
    var objectOne = document.getElementById("object1");
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Zealot DrkFusion's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by AutisticCuckoo
    No quotation marks around the string argument in the first function call.
    Code:
    var objectOne = document.getElementById("object1");
    Done but the a value is still not passed into testVar.

    Thanks for your help
    ZunePoint.com
    Yes, we cover everything and anything zune.

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, the code is IE-only (other browsers don't pollute the global namespace with element names). Set an ID for the hidden field and reference that instead:
    HTML Code:
    <input type="hidden" name="testVar" id="testVar">
    Code:
    document.getElementById("testVar").value = objectOne.style.top;
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

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