...

View Full Version : Writing function output values



RonMcIntire
01-20-2009, 05:14 PM
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>

Philip M
01-20-2009, 06:52 PM
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.

RonMcIntire
01-22-2009, 08:54 PM
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.

Philip M
01-22-2009, 09:53 PM
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." :D:D:D

RonMcIntire
01-23-2009, 07:12 AM
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>

Philip M
01-23-2009, 08:23 AM
Because QtyExtraSongs is the name of the input field and not its value.
Otherwise what you have is fine.


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

RonMcIntire
01-24-2009, 05:55 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum