type mismatch - huh?

R

roN

Hey,

I'm having a littel trouble here. My html looks like this:
HTML:
<select name="new_business" id="new_business"
onchange="add('nb')">
<option value="0">Just started looking</option>
<option value="0">3 - 6 month</option>
<option value="0">6 month to one year</option>
<option value="0">1 year or more</option>
</select>
while my javascript looks like this:
[js]
var score=0; // score
var nb=0; // new business
var sb=0; // starting business
var ac=0; // available capital
var fa=0; // funds available
var ho=0; // home owner
var inc=0; // income
var im=0; //impression
var sec="";
window.onload(0,0);

function add(sec)
{
switch (sec)
{
case 'nb':// new business
nb=parseInt(document.new_business.value);
break
case 'sb':
sb=parseInt(document.00N30000000h5OE.value);
break
case 'ac':
ac=parseInt(document.00N30000000h5OG.value);
break
case 'fa':
fa=parseInt(document.funds.value);
break
case 'ho':
ho=parseInt(document.home.value);
break
case 'inc':
inc=vdocument.income.value);
break
case 'im':
im=document.excited.value;
break
}
score=nb+sb+ac+fa+ho+inc+im;
document.getElementById('postscore').value=score;
document.getElementById('cusscore').innerHTML=score;
var curdate = new Date();
var hour = curdate.getHours();
hour=hour-3; // convert hour from EST to PST
if (score >=70 && hour>=8 && hour<=16) // only between 8am and 5pm PST
{
do something
}
else
{
do something else
}
}
[/js]
Now, I get a type mismatch... it point to the function call in the html...
so i guess it doesn't like the string there but why not, what's wrong?
Shouldn't it work like that?
Any recommodations?

Thanks tons!
Ron
 
R

roN

I'm having a littel trouble here. My html looks like this:
HTML:
<select name="new_business" id="new_business"
onchange="add('nb')">
<option value="0">Just started looking</option>
<option value="0">3 - 6 month</option>
<option value="0">6 month to one year</option>
<option value="0">1 year or more</option>
</select>
while my javascript looks like this:
[js]
var score=0; // score
var nb=0; // new business
var sb=0; // starting business
var ac=0; // available capital
var fa=0; // funds available
var ho=0; // home owner
var inc=0; // income
var im=0; //impression
var sec="";
window.onload(0,0);

function add(sec)
{
switch (sec)
{
case 'nb':// new business
nb=parseInt(document.new_business.value);
break
case 'sb':
sb=parseInt(document.00N30000000h5OE.value);
break
case 'ac':
ac=parseInt(document.00N30000000h5OG.value);
break
case 'fa':
fa=parseInt(document.funds.value);
break
case 'ho':
ho=parseInt(document.home.value);
break
case 'inc':
inc=vdocument.income.value);
break
case 'im':
im=document.excited.value;
break
}
score=nb+sb+ac+fa+ho+inc+im;
document.getElementById('postscore').value=score;
document.getElementById('cusscore').innerHTML=score;
var curdate = new Date();
var hour = curdate.getHours();
hour=hour-3; // convert hour from EST to PST
if (score >=70 && hour>=8 && hour<=16) // only between 8am and 5pm PST
{
do something
}
else
{
do something else
}
}
[/js]
Now, I get a type mismatch... it point to the function call in the html...
so i guess it doesn't like the string there but why not, what's wrong?
Shouldn't it work like that?
Any recommodations?

Thanks tons!
Ron

Sorry I've already found a few bads in my javasacript code: i removed the
"window.onload()" function and i changed the form names to actual names:
function add(sec)
{
switch (sec)
{
case 'nb':
nb=parseInt(document.Form.new_business.value);
break
case 'sb':
sb=parseInt(document.Form.starting.value);
break
case 'ac':
ac=parseInt(document.Form.liquid.value);
break
case 'fa':
fa=parseInt(document.Form.funds.value);
break
case 'ho':
ho=parseInt(document.Form.home.value);
break
case 'inc':
inc=parseInt(document.Form.income.value);
break
case 'im':
im=parseInt(document.Form.excited.value);
break
}

Anyways, the error stays the same :( Can anyone help? :eek:
 
R

roN

K, I did what you recommended, thank you!
I uploaded the page to http://dvdnow.net/callcenter2.php
It is basically a form for our call center and the agent will enter the
clients' answers which will calculate a point score depending on the
answers.

Thank you for your or anybosy's help!
Ron
 
T

Thomas 'PointedEars' Lahn

Randy said:
roN said the following on 7/26/2007 7:16 PM:

The syntax is document.formID.elementName.value, not
document.elementName.value, or, use
document.getElementById('new_business').value

*The* syntax, if there is such a thing, is

document.forms["formID"].elements["elementName"].value

It's both standards compliant and backwards compatible to DOM Level 0.


PointedEars
 
E

Evertjan.

Randy Webb wrote on 02 aug 2007 in comp.lang.javascript:
Thomas 'PointedEars' Lahn said the following on 8/1/2007 1:41 PM:
document.forms["formID"].elements["elementName"].value

Yes, that is a better form to use.
It's both standards compliant and backwards compatible to DOM Level 0.

Both are "standards compliant" and "backwards compatible". The benefit
of the bracket notation is simply the use of certain characters in the
formID and elementName. Otherwise, they are equivalent.

formID wrongly suggests <form ID="formID" ...> to be the standard.

I would prefere as an example:

document.forms["formName"].elements["elementName"].value
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 8/1/2007 1:41 PM:
*The* syntax, if there is such a thing, is

There isn't a "The syntax" in the sense of a better one or worse one. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
One has a drawback that the other doesn't though.
document.forms["formID"].elements["elementName"].value

Yes, that is a better form to use.
^^^^^^^^^^^^^
You are contradicting yourself.
Both are "standards compliant" and "backwards compatible".

No, D::gEBI() is certainly not backwards compatible to DOM Level 0.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 8/2/2007 5:43 AM:
Randy said:
Thomas 'PointedEars' Lahn said the following on 8/1/2007 1:41 PM:
Randy Webb wrote:
roN said the following on 7/26/2007 7:16 PM:
nb=parseInt(document.new_business.value);
The syntax is document.formID.elementName.value, not
document.elementName.value, or, use
document.getElementById('new_business').value
*The* syntax, if there is such a thing, is
There isn't a "The syntax" in the sense of a better one or worse one. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
One has a drawback that the other doesn't though.

document.forms["formID"].elements["elementName"].value
Yes, that is a better form to use.
^^^^^^^^^^^^^
You are contradicting yourself.

And you still have not been able to resolve that contradiction.
No, D::gEBI() is certainly not backwards compatible to DOM Level 0.

I was not referring to gEBI, I was referring to:
document.formName.elementName
document.forms['formName'].elements['elementName']

One is faster, one is more robust in handling certain characters in the
NAME attributes.

The first one is not standards compliant.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Randy said:
Thomas 'PointedEars' Lahn said the following on 8/2/2007 7:06 AM:
Randy said:
Thomas 'PointedEars' Lahn said the following on 8/2/2007 5:43 AM:
Randy Webb wrote:
Thomas 'PointedEars' Lahn said the following on 8/1/2007 1:41 PM:
It's both standards compliant and backwards compatible to DOM Level 0.
Both are "standards compliant" and "backwards compatible". ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
No, D::gEBI() is certainly not backwards compatible to DOM Level 0.
I was not referring to gEBI, I was referring to:
document.formName.elementName
document.forms['formName'].elements['elementName']

One is faster, one is more robust in handling certain characters in the
NAME attributes.
The first one is not standards compliant.

Bah humbug. Who gives a crap about "standards compliant". [...]

You.


PointedEars
 
D

Dr J R Stockton

In comp.lang.javascript message said:
One is faster, one is more robust in handling certain characters in the
NAME attributes.

If the author has full power over the code, that robustness is
unnecessary. Name attributes can be chosen to be valid identifiers,
suited to dot notation.

Bracket notation is useful where there is a set of items to be
processed, and document.forms["XX"+i] can be used in an i loop.

However, I've noted today that NASA's [collaborators'] programmers
prefer the traditional method using eval (e.g. JHU).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top