Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Writing function output values

    All:

    I've got a glitch somewhere and it's not obvious to me. Maybe someone can spot it.

    My problem is that the functions seem to return values but don't display them like they should. I'm testing returned values with a function called sayvalue(item). But when I test "DelTimeCode" the function returns "[Object]". I don't understand. I get returned values from DelTime and DelTitle.

    My approach is to select a radio button option, return a delivery title and a delivery price from the appropriate functions then write the information.

    I think I'm close. Any suggestions or observations of an error in my code?

    I have the following VARIABLES and FUNCTIONS:

    <head>
    var AmtSV;
    var DelTimeCode="";
    var DelTime="";
    var DelTitle="";

    <script language="text/javascript">

    function sayvalue(item)
    {
    alert(item);
    }

    function getAmtSV(code) {
    if (code=='SV01') { AmtSV=AmtSV01;}
    return ("$ " + AmtSV + ".00");
    alert(AmtSV)
    }

    function getDelTitle(code) {
    if (code=='SV01') { DelTitle="Regular Delivery - 8 Hour Window" }
    return (DelTitle);
    }

    function getDelTime(code) {
    if (code=='SV01') {DelTime="8A-5P: 8 Hour Window" }
    return DelTime;
    }

    </script>

    A group of RADIO BUTTONS: (Sample)

    <body>
    <input type="radio" name="DelTimeCode" value="SV01" onclick ="getDelTime('SV01'); getDelTitle('SV01'); getAmtSV('SV01'); sayvalue(DelTimecode)" > 8A-5P: 8 Hour Window ($50)</p>


    I wish to WRITE THE DATA with the following code:

    <td
    <b><script type="text/javascript"> document.write(DelTitle); </script></b>
    </td>
    <td
    <b><script type="text/javascript"> document.write(AmtSV); </script></b>
    </td>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    It is disappointing that you seem to have ignored the advice given in previous posts.

    <head>
    var AmtSV;
    var DelTimeCode="";
    var DelTime="";
    var DelTitle="";

    All this must be within a script!

    <script language="text/javascript">
    Is invalid and not recognised. The correct code is
    <script type = "text/javascript">

    You are using return (DelTitle); at the end of your functions. return where????
    return returns a value to the calling function.

    return ("$ " + AmtSV + ".00");
    alert(AmtSV)

    You cannot have further statements after return. That terminates the function.

    Also, one more time, note that the document.write command must be carried out during the loading of the page. So, if it is attached to any event that executes after the page has loaded, then the whole page will be replaced with the contents of the document.write command.

    I am not being unkind, but you seem to be rather out of your depth. I would very respectfully recommend that you get a better grounding in HTML and Javscript before you proceed further.
    Last edited by Philip M; 01-20-2009 at 07:12 PM.

  • #3
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    Philip:

    Thank you for spotting errors I overlooked. Having tried an endless array of approaches, foggy eyes made it easy to miss even the smallest of mstakes. Your suggestions helped clarify a lot of things and better understand the syntax of the code. My project is now nearly complete.

    Being a newbie to HTML and javascript and trying to make sence of the odities in syntax between javascript and other languages I know, is the prime reason I turned to the experts.

    I mean no disrespect, but I was disappointed in the your lack of patience with me. In the future you may wish to consider exercising the option of not responding to elementary questions from newbies and opt instead to apply your expertise to more challenging inqueries.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by RonMcIntire View Post
    I mean no disrespect, but I was disappointed in the your lack of patience with me. In the future you may wish to consider exercising the option of not responding to elementary questions from newbies and opt instead to apply your expertise to more challenging inqueries.
    Well, at least I did respond to your query, which is more than anyone else bothered to do.

    "I am extraordinarily patient, provided I get my own way in the end."
    Margaret Thatcher, in Observer April 4, 1989
    British politician (1925 - )


    A handful of patience is worth more than a bushel of brains.
    Dutch Proverb



    Long ago, a senior manager of my company said to me "The trouble with you, Philip, is that you don't suffer fools gladly". My response was "Oh, I would not say that. I always thought we got on pretty well."
    Last edited by Philip M; 01-22-2009 at 09:59 PM.

  • #5
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Philip or anyone:

    Now that we have that out of the way, any reason why the following function keeps throwing a NaN when I enter a number and click on the Text box?

    <HTML>
    <head>

    <script type = "text/javascript">
    var UnitExtraSongs=5;

    function getAmtExtraSongs(Qty) {
    var a=parseInt(Qty);
    AmtExtraSongs=parseInt(Qty) * parseInt(UnitExtraSongs);
    alert("AmtExtraSongs = "+AmtExtraSongs);
    alert("Qty = "+Qty);
    alert("a = "+a);
    }

    </script>

    </head>

    <body>


    <p><input type="text" name="QtyExtraSongs" size="20" onclick="getAmtExtraSongs(QtyExtraSongs);"></p>

    </body>

    </HTML>

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Because QtyExtraSongs is the name of the input field and not its value.
    Otherwise what you have is fine.

    Code:
    <html>
    <head>
    <script type = "text/javascript">
    var UnitExtraSongs=5;
    
    function getAmtExtraSongs(Qty) { 
    var a=parseInt(Qty);
    AmtExtraSongs=parseInt(Qty) * parseInt(UnitExtraSongs);
    alert("AmtExtraSongs = "+AmtExtraSongs);
    alert("Qty = "+Qty);
    alert("a = "+a);
    } 
    
    </script>
    
    </head>
    
    <body>
    
    <p><input type="text" name="QtyExtraSongs" size="20" onblur="getAmtExtraSongs(this.value)"></p>
    
    </body>
    
    </html>

    My advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #7
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Philip:

    Ah, yes. Thank you. That makes sense.

    Didn't understand why you used the onblur event for awhile but I do now.

    Thanks again.

    Ron


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •