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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing value from child form to parent form

    hello all,

    i'm newbie in javascript fucntion. here i got problem to passing the value from child popup form to parent form. here my code

    parent form
    Code:
    <script language="JavaScript">
    	function selectItem(){
    		var selindex=document.myForm.myselect.selectedIndex;
    		if (selindex!=0) {
    			document.myForm.item_desc.value=myArray[1]; 
    			document.myForm.item_code.value=myArray[0]; 
    		}
    	}
    </script>
    
    <form  name="myForm"  method="post">
    
    <input  class="input" type="text"  name="item_code" id="item_code" size="30" value ="" /> 
    <input type="button" name="opener" value="Search"  class="myButton" onclick="window.open('child_form.php',
    		'print_view','left=20,top=20,width=750,height=650,toolbar=0,resizable=0,scrollbars=1');return(false);" /> 
    
    <input class="input" type="text"  name="item_desc" id="item_desc" size="80" value ="<?php echo $item_desc?>" />
    </form>

    child_form.php
    Code:
    <script language="JavaScript">
    	function selectItem(){
    		var selindex=document.popUpForm.myselect.selectedIndex;
    		if (selindex!=0) {
    
    	   		window.close();
    			var myArray = document.popUpForm.myselect[selindex].value.split('*');
    			window.opener.document.myForm.item_desc.value=myArray[1];
    			window.opener.document.myForm.item_code.value=myArray[0];
    		}
    	}
    
    </script>
    
    <form name="popUpForm">
    
    $i = 0;
    while ($i < 5){
      <input type="image" src="images/plus.png"  onclick="selectItem();" name="myselect[]" value=<?php echo $i."*".test;?> width="18" height="18"/>      
    
    
    
    $i++;
    }
    </form>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,202
    Thanks
    75
    Thanked 4,342 Times in 4,308 Posts
    You and the rest of the PHP world are seduced by PHP's non-standard way of handling form fields with the same name into thinking that JavaScript will do it the same way.

    NOT AT ALL.

    In PHP code, if you have a form field with a name ending in "[]", then PHP treats that as an array. Not so in any other language, including JavaScript.

    But on top of that, you are trying to treat a multiple set of <input> fields as if they were a single <select> field. That will never work, in any language.

    The is no such thing as selectedIndex for any <form> field type except a <select>.

    Finally, I have no idea what kind of values you are getting for those <input> fields.

    I can't make sense of this:
    Code:
    <?php echo $i."*".test;?>
    Since $1 is just a number from 0 to 4, that means the value= of those <input>s is going to be like this:
    Code:
        value=0.*.xxxx
        value=1.*.xxxx
        value=2.*.xxxx
        value=3.*.xxxx
        value=4.*.xxxx
    Where I have no idea what xxxx will actually be.

    Or if that is even legal PHP code.

    So let's start with that: Bring up that web page in your browser. Right click somewhere in it and then click on "View Page Source" from the right click menu that appears. Copy/paste what you see from that to here.
    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
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    Quote Originally Posted by Old Pedant View Post
    You and the rest of the PHP world are Or if that is even legal PHP code.
    syntactically it is (that's how you call constants), but most of the times PHP needs to fallback to the constant name being converted to a string.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer


  •  

    Posting Permissions

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