Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable in a frame 1

Status
Not open for further replies.

twcman

Programmer
Jun 28, 2001
284
US
I have a page with three frames on it(frNav,frMain and frOder). I have used this in the past with success but am failing on this attempt to retrieve the value of a textbox and pass it to a textbox in another frame. This script is in the <head> document in the frMain frame. Below is the script:

function calcnsend(prod_num, prod_rate){
quant=document.frmcalcnsend.prod_num.value;
totvalue=quant*prod_rate;
parent.frOrder.prod_id.value=totvalue;
}

Here is the form in the <body> of the same document in the frMain frame:

<form action="pricing.cfm" method="post" name="frmcalcnsend" id="frmcalcnsend">
<tr>
<td width="300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#Widget</td>
<td width="150" align="center">
<table width="150" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="30" align="right">$</td>
<td width="120" colspan="2" align="right1.20&nbsp;&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
</td>
<td><input type="text" name="a01a" size="5" onBlur="calcnsend('a01a','1.20');"></td>
</tr>
</form>

The frOrder frame has a textbox named a01a. Using the code above, when the onblur event is activated and a number is typed in the a01a textbox, it generates the error "document.frmcalcnsend.prod_num has no properties".

Any help would be appreciated.

Chris

Chris Scott
The Whole Computer Medical Systems
 
Change:

quant=document.frmcalcnsend.prod_num.value;

...to:

quant=document.frmcalcnsend.elements[prod_num].value;

prod_num is a variable and cannot be used the way you had it.

'hope that helps.

--Dave
 
Thanks,
I made the change and it is now telling me that .elements is null or not an object.

Any ideas?



Chris Scott
The Whole Computer Medical Systems
 
Show me the code as you have it now.

Also, a valid work-around would be:

Code:
function calcnsend([b]prod_numObj[/b], prod_rate){
quant=[b]prod_numObj[/b].value;
totvalue=quant*prod_rate;
parent.frOrder.prod_id.value=totvalue;
}

...

<form action="pricing.cfm" method="post" name="frmcalcnsend" id="frmcalcnsend">
<tr>
    <td width="300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#Widget</td>
    <td width="150" align="center">
    <table width="150" cellspacing="0" cellpadding="0" border="0">
        <tr>
        <td width="30" align="right">$</td>
        <td width="120" colspan="2" align="right1.20&nbsp;&nbsp;&nbsp;&nbsp;</td>
        </tr>
    </table>
    </td>
    <td><input type="text" name="a01a" size="5" onBlur="calcnsend([b]this[/b],'1.20');"></td>
</tr>
</form>

'hope that helps.

--Dave
 
Sorry,
All works well now except it is concantenating the variable instead of adding them.



Chris Scott
The Whole Computer Medical Systems
 
use: parseInt(variableName) or parseFloat(variableName) for quant and prod_rate (e.g., totvalue = parseFloat(quant)*parseFloat(prod_rate)). You might get away with not doing it for prod_rate if you send 1.2 as a parameter to the function instead of '1.20' (with quotes).

--Dave
 
Sorry,
But it is still concantenating the values instead of adding them.



Chris Scott
The Whole Computer Medical Systems
 
Show us the code as you have it so far.

--Dave
 
It is the code from above:

function calcnsend(prod_numObj, prod_rate){
quant=prod_numObj.value;
totvalue=quant*prod_rate;
parent.frOrder.prod_id.value=totvalue;
}

...

<form action="pricing.cfm" method="post" name="frmcalcnsend" id="frmcalcnsend">
<tr>
<td width="300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#Widget</td>
<td width="150" align="center">
<table width="150" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="30" align="right">$</td>
<td width="120" colspan="2" align="right1.20&nbsp;&nbsp;&nbsp;&nbsp;</td>
</tr>
</table>
</td>
<td><input type="text" name="a01a" size="5" onBlur="calcnsend(this,'1.20');"></td>
</tr>
</form>

Chris

Chris Scott
The Whole Computer Medical Systems
 
It's working fine for me in IE6 once I fix the typos in the above code. Is this a copy of your actual code?

<td width="120" colspan="2" align="right1.20&nbsp;&nbsp;&nbsp;&nbsp;</td>

...should be:
<td width="120" colspan="2" align="right">1.20&nbsp;&nbsp;&nbsp;&nbsp;</td>

Also, concatentation comes when two Strings are added together. You do not show any code with addition taking place. Is there additional code to see?

Fix that typo if it exists and post any other relevant code.

Thanks.

--Dave
 
Sorry,
Not a complete list of the function:

function calcnsend(prod_num, prod_rate){
quant = document.frmcalcnsend.elements[prod_num].value;
totvalue=parseFloat(quant)*parseFloat(prod_rate);
parent.frOrder.orderlist.elements[prod_num].value=totvalue;
// total form
for(i=0;i<parent.frOrder.orderlist.elements.length;i++){
quantval=parseFloat(parent.frOrder.orderlist.elements.value);
totvalue1=(totvalue1+quantval);
}
parent.frOrder.orderlist.ordertotal.value=totvalue1;
}



Chris Scott
The Whole Computer Medical Systems
 
Where do you declare totvalue1? My guess is, it reads something like:

var totvalue1 = '0';

If so, you need to change:

totvalue1=(totvalue1+quantval);

...to:

totvalue1=(parseFloat(totvalue1)+quantval);

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top