Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
script in body instead of head
Old 10-05-2005, 05:30 PM script in body instead of head
Average Talker

Posts: 25
Trades: 0
Helpppppppp,

I have to use "initialize" in "body" instead of "head" of a PHP file. I inserted the following in "body":

<script language="javascript" type="text/javascript">
initialize('FrmRegister', 'lstCountry', 'lstState', 'lstCity', new Array('<?=$_SESSION['post']['lstCountry']?>'), new Array('<?=$_SESSION['post']['lstState']?>'), new Array('<?=$_SESSION['post']['lstCity']?>'));
</script>

and the page works fine. However, when I tested the page with a HTML validator for HTML 4.01 Transitional I got an error: The element "script" was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed). Insert "script" in "head".

Can you tell me what can I use instead of "script" to insert "initialize" in the "body"? I tried "body" but I got the same error.
Thx
petre is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-06-2005, 03:34 AM
Skilled Talker

Posts: 96
Name: Tudor Barbu
Trades: 0
Code:
<!DOCTYPE html
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Hello there</title>
</head>
<body>
<script type="text/javascript">
alert('Hello');
</script>
</body>
</html>
This code validates! the "language" attribute doesn`t exists in this DTD...
__________________

Please login or register to view this content. Registration is FREE
Tudor.b is offline
Reply With Quote
View Public Profile Visit Tudor.b's homepage!
 
Old 10-06-2005, 09:27 PM
Average Talker

Posts: 25
Trades: 0
Thanks. I tried it but i doesn't work. I still get the message that I am not allowed to have "script" in "body". And i can not move "script" in head because the form doesn't initilize!!!! Also the code doesn't validate!
petre is offline
Reply With Quote
View Public Profile
 
Old 10-09-2005, 09:11 PM hellllllllllppppppppp
Average Talker

Posts: 25
Trades: 0
Can anybody else help me with this problem???
Thanks.
petre is offline
Reply With Quote
View Public Profile
 
Old 10-10-2005, 07:48 AM
Skilled Talker

Posts: 96
Name: Tudor Barbu
Trades: 0
Post the whole code here...
__________________

Please login or register to view this content. Registration is FREE
Tudor.b is offline
Reply With Quote
View Public Profile Visit Tudor.b's homepage!
 
Old 10-10-2005, 04:50 PM
Extreme Talker

Posts: 160
Trades: 0
Have you tried making the code in to a function and calling it onload?

Put this JavaScript in to the <head>

<script language="javascript" type="text/javascript">
function init()
{
initialize('FrmRegister', 'lstCountry', 'lstState', 'lstCity', new Array('<?=$_SESSION['post']['lstCountry']?>'), new Array('<?=$_SESSION['post']['lstState']?>'), new Array('<?=$_SESSION['post']['lstCity']?>'));
}
</script>

Then change the <body> tag to

<body onload="init()">
ElectricSheep is offline
Reply With Quote
View Public Profile
 
Old 10-13-2005, 05:23 PM
Average Talker

Posts: 25
Trades: 0
My script looks like:
<html>
<head>
<meta tags....................>
<script><...></script> - this script works OK
</head>

<body>
main code here
<script><........></script> - this is the script in question
main code here
</body>
</html>

When I try to validate the HTML I am told that <script> is not allowed within the <body>. When I move the <script> within the <head> with the other scripts, the code doesn't work.

I tried to replace <script> with <body> but in this case I have <body> within <body> and I get an error again.
What else shall i try?
Thanks.
petre is offline
Reply With Quote
View Public Profile
 
Old 10-13-2005, 05:45 PM
Average Talker

Posts: 25
Trades: 0
Hi, I also tried to replace <body> with <body onload...> and it worked. It passed the validation but now any time I open the page I get the error sign even if the code runs OK. When I remove "onload...." from <body> I do not get the message error any more (and of course the code doesn't run)
Any ideas?
Thanks.
petre is offline
Reply With Quote
View Public Profile
 
Old 10-13-2005, 06:01 PM
Average Talker

Posts: 25
Trades: 0
Hi, I did more test and when I replace <body> with <body onload...> it doesn't work if i choose a country that doesn't have states only country name and cities). It does work when the country has states and cities. Is there another any to solve the problem leaving "initialize" within the <body>.? Can I replace <script> with something else? Thanks.
petre is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to script in body instead of head
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27786 seconds with 12 queries