type mismatch - huh?

Discussion in 'Javascript' started by roN, Jul 27, 2007.

  1. roN

    roN Guest

    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
    roN, Jul 27, 2007
    #1
    1. Advertising

  2. roN

    roN Guest

    >
    > 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:
    roN, Jul 27, 2007
    #2
    1. Advertising

  3. roN

    roN Guest

    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
    roN, Jul 27, 2007
    #3
  4. 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$>
    Thomas 'PointedEars' Lahn, Aug 1, 2007
    #4
  5. roN

    Evertjan. Guest

    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)
    Evertjan., Aug 2, 2007
    #5
  6. 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
    Thomas 'PointedEars' Lahn, Aug 2, 2007
    #6
  7. 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$>
    Thomas 'PointedEars' Lahn, Aug 2, 2007
    #7
  8. 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
    Thomas 'PointedEars' Lahn, Aug 2, 2007
    #8
  9. 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.
    Dr J R Stockton, Aug 4, 2007
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Owen

    Output parameters undefined? Huh?

    Jim Owen, Oct 22, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    418
    Rajesh.V
    Oct 22, 2003
  2. VB Programmer
    Replies:
    1
    Views:
    353
    Chris Moore
    Jun 12, 2004
  3. some dude somewhere

    doc types! huh?

    some dude somewhere, Jan 3, 2004, in forum: HTML
    Replies:
    6
    Views:
    434
    Sam Hughes
    Jan 3, 2004
  4. William Trenker

    Huh?!?!? What is it that I'm seeing here?

    William Trenker, Sep 14, 2003, in forum: Python
    Replies:
    6
    Views:
    297
    Gary Feldman
    Sep 15, 2003
  5. programmingzeal
    Replies:
    0
    Views:
    1,114
    programmingzeal
    May 6, 2012
Loading...

Share This Page