Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2009
    Location
    Philippines
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    *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.
    Last edited by Old Pedant; 02-18-2010 at 02:54 AM.
    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.

  • #3
    New Coder
    Join Date
    Dec 2009
    Location
    Philippines
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks Master Old Pedant for your reply.

    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]?

    I have to say, that's pretty ugly code. But what the heck, if it works, it works.
    Hehe

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    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.

  • #5
    New Coder
    Join Date
    Dec 2009
    Location
    Philippines
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts
    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.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •