Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > type mismatch - huh?

Reply
Thread Tools

type mismatch - huh?

 
 
roN
Guest
Posts: n/a
 
      07-26-2007
Hey,

I'm having a littel trouble here. My html looks like this:
HTML Code:
<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=scor e;
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


 
Reply With Quote
 
 
 
 
roN
Guest
Posts: n/a
 
      07-26-2007
>
> I'm having a littel trouble here. My html looks like this:
>
HTML Code:
>          <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=scor e;
> 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?


 
Reply With Quote
 
 
 
 
roN
Guest
Posts: n/a
 
      07-27-2007
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


 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      08-01-2007
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

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

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


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not the
best source of advice on designing systems that use javascript.
-- Richard Cornford, <f806at$ail$1$>
 
Reply With Quote
 
Evertjan.
Guest
Posts: n/a
 
      08-02-2007
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

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      08-02-2007
Randy Webb wrote:
> 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.

>> 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.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      08-02-2007
Randy Webb wrote:
> 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:
>>>> 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.

>>>> 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.


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not the
best source of advice on designing systems that use javascript.
-- Richard Cornford, <f806at$ail$1$>
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      08-02-2007
Randy Webb wrote:
> Thomas 'PointedEars' Lahn said the following on 8/2/2007 7:06 AM:
>> Randy Webb wrote:
>>> 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
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
 
Reply With Quote
 
Dr J R Stockton
Guest
Posts: n/a
 
      08-04-2007
In comp.lang.javascript message <>,
Thu, 2 Aug 2007 06:26:43, Randy Webb <> posted:
>
>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).

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VHDL Type Mismatch error indexed name returns a value whose type does not match programmingzeal VHDL 0 05-06-2012 06:38 AM
type mismatch error amitbadgi@gmail.com ASP .Net 3 08-12-2005 11:23 AM
data type mismatch error amitbadgi@gmail.com ASP .Net 1 08-10-2005 01:04 PM
WORD shutdown - microsoft visual basic Run Time Error 13 - Type Mismatch frodo Computer Support 0 05-20-2004 05:39 PM
Type mismatch using Mozilla ActiveX in place of Microsoft WebBrowser? Noozer Firefox 0 05-19-2004 08:08 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57