SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
-
Aug 16, 2006, 22:50 #1
- 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.
-
Aug 16, 2006, 23:25 #2
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- 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
-
Aug 16, 2006, 23:30 #3
- Join Date
- Jan 2003
- Location
- Canada
- Posts
- 118
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by AutisticCuckoo
Thanks for your help
-
Aug 17, 2006, 01:21 #4
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- 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