Passing Values Between Frames

G

Guest

Hi,
1st, I did a search and could not find any info on this, the Google results
were good, but I'm still have issues...So any help will be great.
I have a frame page, which contains 3 frames (Left, Content, and Footer)

In the content page, I have a checkbox, which value is a number (i.e. 500).
I would like that, when a user clicks on this checkbox, it will send the
value to my LEFT frame.
My left frame has an array, where I'm going to keep track of these
numbers, and then display the total.
I'm at the point were I can send the value to the left frame but only using
'parent.left.document.write.(user_input)
I can't send the value to another variable in the left frame nor can I
reference the variable (content frame) from the left frame side

below is part of my code... I hope this helps.
//FRAME PAGE
<frameset cols="110,*" border="0">
<frame src="nav.html" name="left"/>
<frameset rows="*,50">
<frame src="mainpage.html" name="content"/>
<frame src="footer.html" name="footer"/>
</frameset>
</frameset>
------------------------------------------------------------------
//ARRAY ON NAV page

var numb = new Array();

numb[0] = "0"
numb[1] = "0"
numb[2] = "0"
numb[3] = "0"
numb[4] = "0"
numb[5] = "0"
numb[6] = "0"
numb[7] = "0"
numb[8] = "0"
numb[9] = "0"

var total = parseFloat(numb[0]+parseFloat(numb[1]+parseFloat(numb[2]...etc
------------------------------------------------------------------------

THE CONTENT PAGE WHERE I WILL BE GETTING THE VALUES FROM to pass to the NAV
page

<form name="cartform" action="#">
<input type="checkbox" value="500" name="option1"
onclick="checkedbox(this)" />Add to Cart
</form>

<script type="text/javascript">
function checkedbox(userfield){
{
if (document.cartform.option1.checked)
{
user_input =
parent.content.document.cartform.option1.value
parent.left.document.write(user_input)
}
}
}
</script>

I'm really stuck here, I've tried all kinds of calls, and keep getting the
same error (value is null or not a an object)\
Any help would be greatly appreciated...

Thanks
Joe D.
 
L

Lee

<jc said:
Hi,
1st, I did a search and could not find any info on this, the Google results
were good, but I'm still have issues...So any help will be great.
I have a frame page, which contains 3 frames (Left, Content, and Footer)

In the content page, I have a checkbox, which value is a number (i.e. 500).
I would like that, when a user clicks on this checkbox, it will send the
value to my LEFT frame.
My left frame has an array, where I'm going to keep track of these
numbers, and then display the total.
I'm at the point were I can send the value to the left frame but only using
'parent.left.document.write.(user_input)
I can't send the value to another variable in the left frame nor can I
reference the variable (content frame) from the left frame side

//ARRAY ON NAV page

var numb = new Array();

numb[0] = "0"
numb[1] = "0"
numb[2] = "0"
numb[3] = "0"
numb[4] = "0"
numb[5] = "0"
numb[6] = "0"
numb[7] = "0"
numb[8] = "0"
numb[9] = "0"

var total = parseFloat(numb[0]+parseFloat(numb[1]+parseFloat(numb[2]...etc

How are you trying to assign these values from the content frame?
If a box is checked, where in array "numb" are you trying to put it?
What triggers your code to recalculate the total?
If you convert the values to numbers before you put them into the
array, you won't need to use parseFloat() at all. If you do use it,
it should be as:
total = parseFloat(numb[0])+parseFloat(numb[1])+...
Using parseFloat after you've performed even one "+" operation is
too lage.
 
R

RobG

jc said:
Hi,
1st, I did a search and could not find any info on this, the Google results
were good, but I'm still have issues...So any help will be great.
I have a frame page, which contains 3 frames (Left, Content, and Footer)

In the content page, I have a checkbox, which value is a number (i.e. 500).
I would like that, when a user clicks on this checkbox, it will send the
value to my LEFT frame.
My left frame has an array, where I'm going to keep track of these
numbers, and then display the total.
I'm at the point were I can send the value to the left frame but only using
'parent.left.document.write.(user_input)
I can't send the value to another variable in the left frame nor can I
reference the variable (content frame) from the left frame side

below is part of my code... I hope this helps.
//FRAME PAGE
<frameset cols="110,*" border="0">
<frame src="nav.html" name="left"/>
<frameset rows="*,50">
<frame src="mainpage.html" name="content"/>
<frame src="footer.html" name="footer"/>
</frameset>
</frameset>
------------------------------------------------------------------
//ARRAY ON NAV page

var numb = new Array();

numb[0] = "0"
numb[1] = "0"
numb[2] = "0"
numb[3] = "0"
numb[4] = "0"
numb[5] = "0"
numb[6] = "0"
numb[7] = "0"
numb[8] = "0"
numb[9] = "0"

If you want to initialise an array with 10 elements with values of zero,
then the following is much more concise:

var numb = [];
for (var i=0; i<10; i++){
numb = 0;
}


But it is completely unnecessary, what you seem to need is an object:

var numbObj = {};

var total = parseFloat(numb[0]+parseFloat(numb[1]+parseFloat(numb[2]...etc

To add all the values of the array numb, use a function like:

function sumArray(a)
{
var x=0, i=a.length;
while (i--){
x += +a;
}
return x;
}


But since I've suggested an object, use:

function sumObj(a)
{
var x=0;
for (var prop in a){
x += +a[prop];
}
return x;
}

The unary operator '+' just before the variable ensures it is converted
to a number and replaces your use of parseInt.

------------------------------------------------------------------------

THE CONTENT PAGE WHERE I WILL BE GETTING THE VALUES FROM to pass to the NAV
page

<form name="cartform" action="#">
<input type="checkbox" value="500" name="option1"
onclick="checkedbox(this)" />Add to Cart
</form>

Indent posted code using 2 (preferred) or 4 spaces and wrap manually at
about 70 characters to prevent auto-wrapping.

<script type="text/javascript">
function checkedbox(userfield){
{
if (document.cartform.option1.checked)
{
user_input =
parent.content.document.cartform.option1.value
parent.left.document.write(user_input)
}
}
}

Presumably you will have a number of these and you want all their values
added to the 'numb' object? So put the onclick on the form and update
the object with values from the checked checkboxes. Using an object
means that the checkbox name can be used as the property name and the
value as the value, so you'll have to make the names unique (or maybe
use an id instead).

</script>

I'm really stuck here, I've tried all kinds of calls, and keep getting the
same error (value is null or not a an object)\
Any help would be greatly appreciated...

If this is for a shopping cart, you have a long, long way to go and
remember do not ever rely on client-side scripting to do anything
reliable. Check and validate all data on the server as if your script
did not run (and expect that malicious scripts may have run to change
whatever values you set).

I can't see why this needs frames, I wouldn't use them at all.


Here's something to get you going:

[ mainpage.html ]

<form name="cartform" onclick="updateChecks(this);" action="">
<input type="checkbox" value="500" name="option1">Add 500<br>
<input type="checkbox" value="600" name="option2">Add 600<br>
<input type="checkbox" value="700" name="option3">Add 700<br>
</form>

<script type="text/javascript">

window.onload = function(){document.cartform.reset();}

function updateChecks(f)
{
var formEls = f.elements;
var i = formEls.length;
var el;
while (i--){
el = formEls;
if ('checkbox' == el.type){
if (el.checked){
parent.left.numb[el.name] = el.value;
} else {
parent.left.numb[el.name] = 0;
}
}
}
parent.left.writeSum(parent.left.numb);
}

</script>


[ nav.html ]

<p>The total is: <br><span id="total">&nbsp;</span></p>
<script type="text/javascript">

// Initialise numb
var numb = [];

function sumObj(a)
{
var x=0;
for (var prop in a){
x += +a[prop];
}
return x;
}

function writeSum(a)
{
if (!document.getElementById) return;
var totalEl = document.getElementById('total');
if (totalEl){
totalEl.firstChild.data = sumObj(a);
}
}

</script>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top