Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-18-2010, 02:02 AM   PM User | #1
kingdm
New Coder

 
Join Date: Dec 2009
Location: Philippines
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
kingdm is an unknown quantity at this point
passing values from 1 opened pop up back to parent window

Hello guys.

I've been struggling on how to make this work.

I have a problem in Javascript when it comes to passing of value in a input type field.

page1.html
Code:
<html>
<head><title></title></head>
<form action="" method="post>
<input type="text" name="weight" value=""><a href="hw_calculator.html" target="name" onclick="window.open('hw_calculator.html','name','height=270,width=370,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes'); return false;"> calculate </a>
</form>
</html>
hw_calculator.html
Code:
<html> 
<head>
<title> 
Height Converter (Metric/Standard)
</title>
</head>
<body>
<FORM>
<INPUT type=hidden value="(Math.round((P.value * 0.45359)*100))/100" name=K_expr> 
<INPUT type=hidden value="(Math.round((K.value / 0.45359)*100))/100" name=P_expr> 
<INPUT type=hidden value="(Math.round((F.value * 30.48 + I.value * 2.54)*100))/100" name=C_expr> 
<INPUT type=hidden value="(Math.floor(C.value / 30.48))" name=F_expr> 
<INPUT type=hidden value="(Math.round(((C.value - (Math.floor(C.value / 30.48) * 30.48)) / 2.54)*100))/100" name=I_expr> 
<INPUT type=hidden value="(Math.round(P.value * 0.45359))" name=K_exprrnd> 
<INPUT type=hidden value="(Math.round(K.value / 0.45359))" name=P_exprrnd> 
<INPUT type=hidden value="(Math.round(F.value * 30.48 + I.value * 2.54))" name=C_exprrnd> 
<INPUT type=hidden value="(Math.floor(C.value / 30.48))" name=F_exprrnd> 
<INPUT type=hidden value="(Math.round((C.value - (Math.floor(C.value / 30.48) * 30.48)) / 2.54))" name=I_exprrnd>
<h2>Height Converter</h2>
<table border="0" bgcolor="#FFFF99" cellspacing="6" cellpadding="6">
<tr>
<td colspan>
<p class="conv" style="margin-top: 10px; margin-bottom: 10px"><b>STANDARD</b></p>
</td>
<td></td>
<td colspan>
<p class="conv" style="margin-top: 10px; margin-bottom: 10px"><b>METRIC</b></p>
</td>
</tr>
<tr>
<td>
<p class="conv" style="margin-top: 10px; margin-bottom: 10px">Feet :&nbsp;<input maxLength=1 size=1 value=0 name=F>&nbsp;Inches :&nbsp;<input maxLength=2 size=1 value=0 name=I>
</td>
<td>
<p class="conv" style="margin-top: 10px; margin-bottom: 10px">&nbsp;=&nbsp;</p>
</td>
<td>
<p class="conv" style="margin-top: 10px; margin-bottom: 10px"><input maxLength=3 size=1 value=0 name=C disabled>&nbsp;cm.</p>
</td>
</tr>
<tr>
<td class="conv" colspan="2">
<input type="button" name="Taste" value="Calculate"
onclick="if (rounded.checked == true) {
eval('C.value = ' + this.form.C_exprrnd.value);
eval('K.value = ' + this.form.K_exprrnd.value) }
else {
eval('C.value = ' + this.form.C_expr.value);
eval('K.value = ' + this.form.K_expr.value)
}">
<INPUT type=checkbox name="rounded" value="rounded" checked disabled><font size="1" face="Verdana">Rounded Result</font>
</td>
</tr>
</table>
<p class="conv" style="margin-top: 10px; margin-bottom: 10px">
</body>
</html>
I want the value of
Code:
<input maxLength=3 size=1 value=0 name=C disabled>
, this is from hw_calculator.html, to be passed on the
Code:
<input type="text" name="weight" value="">
on page1.html. How can I do this?

Huge thanks.
kingdm is offline   Reply With Quote
Old 02-18-2010, 02:38 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
*WHEN* do you want it to happen???

Do you want it to happen at the same time C.value is changed by your button click??

If so, that's easy.
Code:
<input type="button" name="Taste" value="Calculate"
   onclick="if (rounded.checked == true) {
               eval('C.value = ' + this.form.C_exprrnd.value);
               eval('K.value = ' + this.form.K_exprrnd.value) }
             else {
                eval('C.value = ' + this.form.C_expr.value);
                eval('K.value = ' + this.form.K_expr.value)
            }
            opener.forms[0].weight.value = this.form.C.value;"
    />
Would be better to give a name to the form in the opener, so you don't have to use forms[0], of course.


I have to say, that's pretty ugly code. But what the heck, if it works, it works.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 02-18-2010 at 02:54 AM..
Old Pedant is offline   Reply With Quote
Old 02-18-2010, 02:51 AM   PM User | #3
kingdm
New Coder

 
Join Date: Dec 2009
Location: Philippines
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
kingdm is an unknown quantity at this point
Thanks Master Old Pedant for your reply.

Quote:
Do you want it to happen at the same time C.value is changed by your button click??
Yes, that's exactly what I want to happen. Why use forms[0]?

Quote:
I have to say, that's pretty ugly code. But what the heck, if it works, it works.
Hehe
kingdm is offline   Reply With Quote
Old 02-18-2010, 02:53 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Quote:
How could I do it possibly?
By using the code I gave you.

I just went back and colored in my change, since apparently you didn't see it.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 02-18-2010, 03:04 AM   PM User | #5
kingdm
New Coder

 
Join Date: Dec 2009
Location: Philippines
Posts: 27
Thanks: 3
Thanked 0 Times in 0 Posts
kingdm is an unknown quantity at this point
I modify the code based on the code you gave me master Old Pedant. But it's not working. I think there is a problem regarding my form and the opener.forms[0]. I will post the whole form on page1.html, can you suggest if what seems to be the error in here.

This is the full page1.html

Code:
<form method="post" action="form3_processing.php">
			<label>Birth Place
			<span class="small">place you were born</span>
			</label>
			<input type="text" name="bplace" maxlength="50" value="<?php echo $_SESSION['bplace']; ?>" />
			
			<label>Skin Complexion
			<span class="small">choose one</span>
			</label>&nbsp;&nbsp;
			<select name="skin">
			<option value="<?php echo $_SESSION['skin']; ?>" selected="selected"><?php echo $_SESSION['skin']; ?></option>
			<option value=""></option>
			<option value="Light">Light</option>
			<option value="Fair">Fair</option>
			<option value="Dark">Dark</option>
			</select><br /><br />
			
			<label>Color of Eyes	
			<span class="small">choose one</span>
			</label>&nbsp;&nbsp;
			<select name="eyes">
			<option value="<?php echo $_SESSION['eyes']; ?>" selected="selected"><?php echo $_SESSION['eyes']; ?></option>
			<option value=""></option>
			<option value="Black">Black</option>
		    <option value="Blue">Blue</option>
		    <option value="Amber">Amber</option>
		    <option value="Gray">Gray</option>
		    <option value="Green">Green</option>
		    <option value="Heterochromia">Heterochromia</option>
			</select><br /><br />
			
			<label>Weight
			<span class="small">kilograms (kg)<a href="ww_calculator.html" target="name" onclick="window.open('ww_calculator.html','name','height=270,width=370,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes'); return false;"> calculate </a></span>			
			</label>
			<input type="text" name="weight" maxlength="3" value="<?php echo $_SESSION['weight']; ?>" />
			<label>Height
			<span class="small">centimeters (cm)<a href="hw_calculator.html" target="name" onclick="window.open('hw_calculator.html','name','height=270,width=370,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes'); return false;"> calculate </a></span>
			</label>
			<input type="text" name="height" maxlength="3" value="<?php echo $_SESSION['height']; ?>" />
			<?php echo $button; ?>
		</form>
I highlighted the part I'm concern into. Thank you so much master.
kingdm is offline   Reply With Quote
Old 02-18-2010, 05:51 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Try giving your <form> a name. Example:
Code:
<form name="HWINFO" method="post" action="form3_processing.php">
And then reference it by name in the popup window:
Code:
    opener.document.HWINFO.weight.value = this.form.C.value;"
And I just noticed that I left "document." out of my original answer.

It should have been
Code:
    opener.document.forms[0].weight.value = this.form.C.value;"
Sorry about the typo!
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 04:00 AM.


Advertisement
Log in to turn off these ads.