Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by TheInnovator
at 2024-07-21 18:06:41
Point:500 Replies:5 POST_ID:829064USER_ID:11967
Topic:
JavaScript;;
I have a js file and I'm playing around with object literals but it's not working.
Any ideas why?
Thanks!
Any ideas why?
Thanks!
Expert: duncanb7 replied at 2024-07-21 19:41:40
Thanks for your points
Have a nice day
Duncan
Have a nice day
Duncan
Author: TheInnovator replied at 2024-07-21 19:32:12
Thanks! That's something I should have known.
Accepted Solution
Expert: duncanb7 replied at 2024-07-21 19:10:25
500 points EXCELLENT
it is because the html page is not loaded completely before javascript running,
please try this by adding init() function with onload in body tag
Duncan
please try this by adding init() function with onload in body tag
Duncan
<!DOCTYPE html><html><head> <title></title> <script type="text/JavaScript"> function init(){ var hotel = { name: 'Sunset', rooms: 65, Booked: 15, checkAvailability: function() { return this.rooms - this.Booked; } }; var elName = document.getElementById('hName'); elName.textContent = hotel.name; var rmLeft = document.getElementById('hRoomLeft'); rmLeft.textContent = hotel.checkAvailability();} </script></head><body onload="javascipt:init();"> <table> <tr> <td>Hotel Availability</td> </tr> <tr> <td>Hotel: </td> <td><div id="hName"></div></td> </tr> <tr> <td>Rooms Left: </td> <td><div id="hRoomLeft"></div></td> </tr> </table></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:42:43:
Or you try this , change script location
<!DOCTYPE html><html><head> <title></title></head><body> <table> <tr> <td>Hotel Availability</td> </tr> <tr> <td>Hotel: </td> <td><div id="hName"></div></td> </tr> <tr> <td>Rooms Left: </td> <td><div id="hRoomLeft"></div></td> </tr> </table> <script type="text/JavaScript"> var hotel = { name: 'Sunset', rooms: 65, Booked: 15, checkAvailability: function() { return this.rooms - this.Booked; } }; var elName = document.getElementById('hName'); elName.textContent = hotel.name; var rmLeft = document.getElementById('hRoomLeft'); rmLeft.textContent = hotel.checkAvailability(); </script></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:
Author: TheInnovator replied at 2024-07-21 18:40:28
The file was attached but here you go....
<!DOCTYPE html><html><head> <title></title> <script type="text/JavaScript"> var hotel = { name: 'Sunset', rooms: 65, Booked: 15, checkAvailability: function() { return this.rooms - this.Booked; } }; var elName = document.getElementById('hName'); elName.textContent = hotel.name; var rmLeft = document.getElementById('hRoomLeft'); rmLeft.textContent = hotel.checkAvailability(); </script></head><body> <table> <tr> <td>Hotel Availability</td> </tr> <tr> <td>Hotel: </td> <td><div id="hName"></div></td> </tr> <tr> <td>Rooms Left: </td> <td><div id="hRoomLeft"></div></td> </tr> </table></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:
Expert: duncanb7 replied at 2024-07-21 18:35:58
From the information you provide, I think it is because x element has error. If you can provide more x element information, it will assist to solve your issue.
Duncan
Duncan