general knorr
05-26-2005, 07:45 PM
I have been able to get this javaScript to work using Arrays , but when I rewrite all the code to attempt it by creating new objects with an 'Object constructer function' I get lots of "not an object" and "undefined" errors.
My browser is ie5.0, the editor is Evrsoft 1stPage2000. Does my editor support new Object creation ? :confused:
The Evrsoft editor has an option that is supposed to let you open files in another browser but it doesn't seem to work. Anyone know anything about that ? :confused:
So assumming it's not the editor browser's fault. Here's the javaScript that's not going so hot.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>TestQuip</title>
<script language="javascript1.2" type="text/javascript">
<!-- Invi script
function Test(question,choiceList){
this.question = question;
this.choiceList = choiceList;
this.insertAnswers = insertAnswers;
}
var question01 = new Test("What is the glarp question \?","darn");
var question02 = new Test("Who let the dawgs out \? glarp","Who Who \!");
function insertAnswers()
{
var Q = this.question.value;
var g = Q.indexOf("glarp");
frontHalfQuestion = Q.substring(0,g);
var ball = g+5;
backHalfQuestion = Q.substring(ball,Q.length);
return frontHalfQuestion,choiceList,backHalfQuestion
}
// preemo -->
</script>
</head>
<body>
for (j=0; j<=Test.length-1;j++)
{
document.write('<P>Question ',j+1,' of ',Test.length,'</P>');// writes "question 1 of 2"
insertAnswers(this.question,this.choiceList);//worked when it was Arrays and question[j]
document.write'<P>',frontHalfQuestion+choiceList+backHalfQuestion,'</P>');
}
</script>
</body>
</html>
the hard part for me is understanding the "instance of" stuff. I've read, studied, all the FAQ's and tutorials here. They helped me realize what the problem wasn't.
I thought the whole Idea behind a construtor function like the one above was that 'Test' would become a new Object , 'question' would become a property of 'Test' , would have a value and be defined. In this case Test.question.value would equal "What is the glarp question \?". My machine doesn't return that, I get the error message 'Test.question is not an object'.
so, before KOR rips me for being too wordy, I've tried to access the values of the 'question' property a hundred ways.
Test.question.value
Test["question"].value
Test[0].question
Test.this.question
Test[0].question[0].value
this.question
question
question[0]
Test.prototype.question
nothing has worked :eek:
I found that Test.length works. (returns 2 like it should) .
My browser is ie5.0, the editor is Evrsoft 1stPage2000. Does my editor support new Object creation ? :confused:
The Evrsoft editor has an option that is supposed to let you open files in another browser but it doesn't seem to work. Anyone know anything about that ? :confused:
So assumming it's not the editor browser's fault. Here's the javaScript that's not going so hot.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>TestQuip</title>
<script language="javascript1.2" type="text/javascript">
<!-- Invi script
function Test(question,choiceList){
this.question = question;
this.choiceList = choiceList;
this.insertAnswers = insertAnswers;
}
var question01 = new Test("What is the glarp question \?","darn");
var question02 = new Test("Who let the dawgs out \? glarp","Who Who \!");
function insertAnswers()
{
var Q = this.question.value;
var g = Q.indexOf("glarp");
frontHalfQuestion = Q.substring(0,g);
var ball = g+5;
backHalfQuestion = Q.substring(ball,Q.length);
return frontHalfQuestion,choiceList,backHalfQuestion
}
// preemo -->
</script>
</head>
<body>
for (j=0; j<=Test.length-1;j++)
{
document.write('<P>Question ',j+1,' of ',Test.length,'</P>');// writes "question 1 of 2"
insertAnswers(this.question,this.choiceList);//worked when it was Arrays and question[j]
document.write'<P>',frontHalfQuestion+choiceList+backHalfQuestion,'</P>');
}
</script>
</body>
</html>
the hard part for me is understanding the "instance of" stuff. I've read, studied, all the FAQ's and tutorials here. They helped me realize what the problem wasn't.
I thought the whole Idea behind a construtor function like the one above was that 'Test' would become a new Object , 'question' would become a property of 'Test' , would have a value and be defined. In this case Test.question.value would equal "What is the glarp question \?". My machine doesn't return that, I get the error message 'Test.question is not an object'.
so, before KOR rips me for being too wordy, I've tried to access the values of the 'question' property a hundred ways.
Test.question.value
Test["question"].value
Test[0].question
Test.this.question
Test[0].question[0].value
this.question
question
question[0]
Test.prototype.question
nothing has worked :eek:
I found that Test.length works. (returns 2 like it should) .