Click to See Complete Forum and Search --> : new to javascript~ please help!


schmikes
10-25-2003, 03:58 AM
hi~ i am new to javascript and html. i am trying to write a web page by javascript.

here is what i wrote but it shows nothing:
<html><head><title>Display three</title></head>
<body><SCRIPT language="javaScript">
<!-- begin script
document.write("hey")
document.write("Joe said,"Hi, how are you doing?!"")<br>
document.write("Angel said,"Good, thanks! is this your new car?"")<br>
document.write("Joe said"Yeah, that\'s mine!"")
// end script-->
</SCRIPT>
</body></html>

is there any problems in it? pleas tell me~
thank you very much!

sciguyryan
10-25-2003, 04:11 AM
Yes, your sentances would be cut in half as you have closed your speech marks half way through the phrase.
2 - I dont think that you can have an open <BR> within a script like that:

try this instead:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>Write</TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--
document.write("hey<BR>")
document.write("Joe said, \"Hi, how are you doing?!\"<BR>")
document.write("Angel said, \"Good, thanks! is this your new car?\"<BR>")
document.write("Joe said \"Yeah, that\'s mine!\"")
//-->
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>

schmikes
10-25-2003, 04:18 PM
sciguyryan, thanks!
I have another problem:

<HTML><HEAD><TITLE> TIME </TITLE>
<SCRIPT LANGUAGE="JAVASCRIPT>
dt=new Date()
dat1= (dt.getMonth()+1)+"/"
dat2= dt.getDate()+"/"
dat3= dt.getYear()
newDate= dat1+dat2+dat3
document.write("<BR>")
document.write("<h2> "+newDate+"</h2>")
document.write("<br><H2 align=center> This document was last modified
"+document.lastModified+"</h2>")
document.write("<h4 align=center> This page is still under construction</h4>")
<SCRIPT></HEAD><BODY></BODY></HTML>

i want to show the time by writing this one.
but it shows nothing agian /.\
sigh~ javascript is difficult.
can you guys please help again?
Thanks!

Jona
10-25-2003, 04:45 PM
First of all, you have no DTD (doctype), which must be included in all documents. Second, your HTML is not valid and makes use of JavaScript without providing alternative text or data for those without JavaScript enabled on their user agents (browsers). Your code should be as follows:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
&nbsp;"http://www.w3.org/TR/html4/stirct.dtd">
<HTML lang="en-US">
<HEAD><TITLE> Time </TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT type="text/javascript"><!--
var dt=new Date();
dat1= (dt.getMonth()+1)+"/";
dat2= dt.getDate()+"/";
dat3= dt.getYear();
newDate= dat1+dat2+dat3;
//--><SCRIPT></HEAD>
<BODY>
<p>This is the information that anyone and everyone will see on the page.</p>
<script type="text/javascript"><!--
document.write("<p>");
document.write("<h1 style=\"font-size:18px;\">"+newDate+"</h1>");
document.write("<H2 style=\"text-align:center;\">This document was last modified "+document.lastModified+"</h2>");
document.write("<h4 style=\"text-align:center;\">This page is still under construction</h4>");
document.write("This is the paragraph that only users with JavaScript enabled will see.</p>");
//--></script></BODY></HTML>


[J]ona

schmikes
10-26-2003, 01:31 AM
Hi, Jona, thanks for your help.
i copied yours and paste it in the notepad and try to show it in the internet explorer, but it still showed nothing.

is there still any problems?

thanks!

schmikes
10-26-2003, 02:30 PM
can anyone help me with that problem please?
Thank you!

fredmv
10-26-2003, 04:35 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML lang="en-US">
<HEAD><TITLE> Time </TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT type="text/javascript"><!--
var dt=new Date();
dat1= (dt.getMonth()+1)+"/";
dat2= dt.getDate()+"/";
dat3= dt.getYear();
newDate= dat1+dat2+dat3;
//--></SCRIPT></HEAD>
<BODY>
<p>This is the information that anyone and everyone will see on the page.</p>
<script type="text/javascript"><!--
document.write("<p>");
document.write("<h1 style=\"font-size:18px;\">"+newDate+"</h1>");
document.write("<H2 style=\"text-align:center;\">This document was last modified "+document.lastModified+"</h2>");
document.write("<h4 style=\"text-align:center;\">This page is still under construction</h4>");
document.write("This is the paragraph that only users with JavaScript enabled will see.</p>");
//--></script></BODY></HTML>;)

Jona
10-26-2003, 07:34 PM
I need to make a note not to copy and paste people's original code... The first line that shows stirct.dtd should be strict.dtd

Thanks, fredmv.

[J]ona

fredmv
10-26-2003, 09:42 PM
No problem; simple typos are among the hardest errors to find. I also fixed the typo in the DTD. ;)

schmikes
10-27-2003, 12:24 PM
sorry~ i was not mean to copy it

by the way, i have another questions:
<HTML><HEAD><TITLE>My JavaScript page</TITLE><SCRIPT>

ans = promp("Are you sure you want to do that?","")
if (ans) {
alert("You said"+ans)
}
else{
alert("You refused to answer")

</SCRIPT></HEAD><BODY><H2>Welcome!</H2></BODY></HTML>

Jona
10-27-2003, 12:27 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
&nbsp;"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head><title>My JavaScript Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript"><!--
var ans = prompt("Are you sure you want to do that?","");
if(ans!=null){
alert("You said "+ans);
} else {
alert("You didn't say anything!");
}
//--></script>
</head>
<body>
<p>JavaScript page</p>
</body></html>


[J]ona

schmikes
10-27-2003, 12:42 PM
thanks sooooo much for the help so fast, but i have my last and final question

<html><head><title>Using Break Statement</title><script>
for (i=100;i>0; --1){
document.write(i+"<br>")
if (i%17==0) break
} </script></body></html>


thanks so much jona

Jona
10-27-2003, 01:26 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
&nbsp;"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head><title>For loop</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<p>This page is an example of JavaScript's for() looping ability. This page does not contain content for users without JavaScript, and therefore you will not see the content which would otherwise be displayed below.</p>
<script type="text/javascript"><!--
document.write("<p>");
for(i=100; i>0; i--){
&nbsp;&nbsp;document.write(i+"<br>");
&nbsp;if(i%17==0) break;
}
document.write("</p>");
//--></script>
</body></html>


[J]ona

schmikes
10-28-2003, 11:21 PM
I see~
i can do all these now!
Thank you soooooooooooo much!!!!