Jump to content

How to sort data from child window


The_Dude_1978

Recommended Posts

Hi there,

 

I'm not an experienced scripter. What I've got is the following: a index page that calls the child window

 

index.html

<html>
<head>
<script language="javascript"> 
function openwindow() 
{ 
retval=window.showModalDialog("popup.html") 
document.getElementById('text1').value=retval 
} 
</script>

</head>
<body>
<input name=text1 type=text readonly>
<input type=button onclick="javascript:openwindow()" value="Open window.."> 

</div>
</body>
</html>

 

popup.html

<html>
<head>
<script type="text/javascript">
function calculate(f)
{
var photo = f.photos;
var ptext = f.photostext;
var pitem = f.photositem;
var result = 0;
var items = '';
for(var i=0;i<photo.length;i++)
{
if(photo[i].checked)
{
result+=parseFloat(ptext[i].value);
items+=pitem[i].value+'\n';
}
}
f.answer.value=Number(result).toFixed(2);

//if you want to fix to 2 decimal places
//f.answer.value=Number(result).toFixed(2);

window.returnValue=f.allitems.value=items;

}
</script>
<style type="text/css">
.box1 { float:left; 
	width:500px;
	clear:left;
	}
</style>

<script language="javascript">
<!-- Hide from browsers lacking javascript
window.onload=function()
{
document.getElementById("close").onclick=function(){window.close()};
};
// End hiding -->
</script>
</head>
<body>
<div id="photos">

<form name="myform" method="post" onSubmit="formSubmit()" >
Choose the product options you want to order<br>
<div class="box1">
<input type="checkbox" name="photos" id="photos" onclick="calculate(this.form)">
<input type="hidden" name="photostext" id="photostext" value="1.50" onchange="calculate(this.form)">15x15 (1,50)
<input type="hidden" name="photositem" id="photositem" value="15x15" onchange="calculate(this.form)">

</div>
<br>
<div class="box1">
<input type="checkbox" name="photos" id="photos" onclick="calculate(this.form)">
<input type="hidden" name="photostext" id="photostext" value="2.00" onchange="calculate(this.form)">15x30 (2,00)
<input type="hidden" name="photositem" id="photositem" value="15x30" onchange="calculate(this.form)">

</div><br>
<div class="box1">
<input type="checkbox" name="photos" id="photos" onclick="calculate(this.form)">
<input type="hidden" name="photostext" id="photostext" value="3.20" onchange="calculate(this.form)">30x30 (3,20)
<input type="hidden" name="photositem" id="photositem" value="30x30" onchange="calculate(this.form)">

</div><br>
<div class="box1">
Total <input type="text" name="answer" size="5"><textarea name="allitems" rows="5"></textarea>
</div>
<div class="box1">
<input type="submit" name="close" value="submit" /> 
</div>
</form>
</div>
</body>
</html>

 

With this code it sets the product after eachother without spaces in the textarea.

 

And I can't seem to find out how to sort the data of each product into:

 

Description (checkbox description) > product > price > Total

 

I need this in table and in a form to post to the shopping cart.

 

Can you help me out?

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.