View Full Version : Passing value from child form to parent form

12-13-2011, 04:13 AM
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

<script language="JavaScript">
function selectItem(){
var selindex=document.myForm.myselect.selectedIndex;
if (selindex!=0) {

<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?>" />


<script language="JavaScript">
function selectItem(){
var selindex=document.popUpForm.myselect.selectedIndex;
if (selindex!=0) {

var myArray = document.popUpForm.myselect[selindex].value.split('*');


<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"/>


Old Pedant
12-13-2011, 10:57 PM
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.


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:

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


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.

12-14-2011, 06:25 PM
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.