View Full Version : javascript
chaiwat
08-20-2004, 10:56 AM
hello,
I have one page javascript but it doesn't work it not show up on normal page and preview page in frontpage. can I paste a code in here. My frontpage take javascript but I want to find a wrong thing in this page but I don't know where.can I paste a code in here please.
chaiwat
Goldilocks
08-20-2004, 11:15 AM
Hi Chaiwat. Yes you can post your code in here, then we'll see if we can help you.
chaiwat
08-20-2004, 11:42 PM
Hello,
This is my code. I want like auto mark.
<html>
<head>
<title>New Page 2</title>
<script language="javascript">
var m,n,checkDo,countDo,checkTrue;
var myAnswer,myBadAnswer,noAnswerList,answerList;
var ask;
var choice=new Array();
var answer=new Array();
function Sheets(num,totalChoice)
{ document.write("<span ID=NUM"+num+"></span");
document.write("<p style=font-family:AngsanaUPC;
font-size:20;color:#aa0000;>");
document.write("<img ID='indicator' src='icon/normal.ico' > number");
document.write((num+1)+" "+ask+"<form name='test'
style=font-family:AngsanaUPC;font-size:18;color:blue; >");
for(n=0;n<totalChoice;n++)
{ document.write("<input type='radio' name='choose' value="+n+" >");
document.write("<span ID='select'>"+choice[n]+"</span><br>");
}
document.write("</form>");
document.write("</p>");
}
document.write("<h1> When you take test </h1>");
ask="quetion";
answer[0]=0;
choice[0]="h";
choice[1]="f";
choice[2]="b";
choice[3]="g";
choice[4]="t";
choice[5]="w";
Sheet(0,6);
ask="question2";
answer[1]=2;
choice[0]="c";
choice[1]="r";
choice[2]="e";
choice[3]="d";
choice[4]="g";
choice[5]="q";
Sheets(1,6);
/
function DynamicButton()
{ MENU.style.posLeft=document.body.scrollLeft+300;
MENU.style.posTop=document.body.scrollTop+100;
}
function checkAnswer()
{ checkTrue=0;
countDo=0;
myAnswer=" ";
myBadAnswer=" ";
noAnswerList=" ";
answerList=" ";
for(m=0; m<answer.length; m++)
{ checkDo=false;
for(n=0; n<document.test[m].elements.length; n++)
{ if(document.test[m].elements[n].checked)
{ checkDo=true; countDo++;
if(document.test[m].elements[n].value==answer[m])
{ indicator[m].src="icon/right.ico";
checkTrue++; myAnswer+=((m+1)+',');
}
else
{ indicator[m].src=" icon/wrong.ico";
myBadAnswer+=((m+1)+',');
}
answerList+=((m+1)+',');
break;
}
}
if(checkDo==false)
{ indicator[m].src=" icon/normal.ico";
noAnswerList+=((m+1)+',');
}
}
}
function showScore()
{ checkAnswer();
var say,degree;
degree=(checkTrue*100)/test.length;
if(countDo==0) say="did not do";
else if(degree==0) say="you can not do";
alert("all test"+test.length+" "+"\nyou can do"
+countDo+" is "+answerList+" \nnot do "+(test.length-countDo)3
+" is "+n0AnswerList+" \ncorrect "+checkTrue+" is \nthat is"
+((checkTrue*100)/countDo)+"percent for work\nor is"
+((checkTrue*100)/test.length)+" percent for all \nby right answer"
+myAnswer+"\nwrong one"+myBadAnswer+"\nfor percent that count"+say
+"\n so now you know");
}
<body bgcolor="#ffaaaa" onscroll="DynamicButton()">
<span ID=MENU style=position:absolute;left:400;top:100;>
<button onclick="showScore()">
check answer and show score</button><br>
</span>
</body
</head>
</html>
</script>
could you help. It not show anything in normal page.
chaiwat
senshi
08-22-2004, 02:51 PM
You need to pay attention to what and where yo put your script and how you form strings within quotes too.
if you have...
<img src="http:/myserver/img01.gif" alt="anImage">
and you want to output it using documnet.write....
you have to wrap the string like so...
documnet.write("<img src=\"http:/myserver/img01.gif\" alt=\"anImage\">")
this wont work because the script only sees...
documnet.write("<img src="http:/myserver/img01.gif" alt="anImage">")
"<img src=" part as the string.
things further get complicated when you start adding in variables to a string or document.write call.
documnet.write("<img src=\""+imgURL+"\" alt=\""+altText+"\">")
so if your not careful, you can get it wrong.
if you put your scripts into a HTML file, your scripts shouldbe placed in the header, the head is found between the <head></head> tags in a document, looking at your script, you have misplace tags and have various, sorry numerous javascript errors.
I have had a quick play with the script and its down to coding issues.
pay special attention because strings, making strings, adding string and generally string cause no end of headaches, when you get them right and use to handleing them, it becomes childs play
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.