Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Passing Values Between Frames

Reply
Thread Tools

Passing Values Between Frames

 
 
Guest
Posts: n/a
 
      12-11-2005
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.



 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      12-12-2005
<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.





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


 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      12-12-2005
<jc wrote:
> 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[i] = 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[i];
}
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[i];
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>


--
Rob
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Frames or not Frames... Ale HTML 17 08-05-2005 12:10 AM
Link needed to go from a non-frames page to a Frames page, and load a particular frame. How? - Newbe Philip HTML 3 06-28-2004 03:06 PM
Passing the values between frames Gibs ASP .Net 1 01-23-2004 08:37 PM
From Frames to no frames? Powerslave2112 HTML 2 01-20-2004 10:30 PM
Re: Passing objects between pages and frames... dave wanta ASP .Net 0 07-04-2003 12:10 PM



Advertisments