Jump to content

Pass value from parent to child window


crims0nluv

Recommended Posts

Hi there,

 

I have a page that user click on a link "Select from address book". then it pops up a child window that display a list of members.

 

This is my query

//gid is when user click on a group in the address book, then will filter out all the users in the group

  if($_GET['gid']) {

$gid=$_GET['gid'];

$contacts=mysql_query("SELECT c.*,cg.* FROM contact c, contact_group cg WHERE user__id='$userid' and cg.contact__id=c.contact_id and cg.group__id='$gid'");

      } else {

$contacts=mysql_query("SELECT * FROM contact WHERE user__id='$userid'");

    }

 

//display the result

while($row=mysql_fetch_array($contacts)) { ?>

  <str><td width="26" align="left" height="20"><input type="checkbox" name="select_contact" value="<?= $row['contact_number'] ?>"></td>

  <td width="298" align="left"><? echo $row['contact_firstname']; ?></td>

  </tr>

<? } ?>

 

This is my submit button. Should pass down the value to the parent page.

<input type="button" name="submit" value="Submit" onclick="post_value();">

 

 

function post_value(){

var c_value = "";

for (var i=0; i < document.form1.select_contact.length; i++)

  {

  if (document.form1.select_contact.checked)

      {

      c_value = c_value + document.form1.select_contact.value + "\n";

      }

  }

  opener.document.form.sendto.value=c_value;

  self.close();

}

 

This script works if the all the members in the address book is listed out, but when user clicked on a group and click submit, the javascript couldn't aget "document.form1.select_contact.length". it gives me undefined variable when I tried to print.

Any solution??

 

Thanks!!

Link to comment
Share on other sites

First thing to note is your if statement. I would use something like this:

 

<?php
// gid is when user click on a group in the address book, then will filter out all the users in the group
$gid=$_GET['gid'];

if(isset($gid)) {
$contacts=mysql_query("SELECT c.*,cg.* FROM contact c, contact_group cg WHERE user__id='$userid' and cg.contact__id=c.contact_id and cg.group__id='$gid'");
} else {
$contacts=mysql_query("SELECT * FROM contact WHERE user__id='$userid'");
}
?>

 

As for your results, the problem may lie in the value. You seem to have an extra = in there. Try this.

 

<?php
//display the result
while($row=mysql_fetch_array($contacts)) {
echo '<str><td width="26" align="left" height="20"><input type="checkbox" name="select_contact" value="'.$row['contact_number'].'">';
echo '</td><td width="298" align="left">'.$row['contact_firstname'].'</td></tr>';
}
?>

 

Lastly, a line in that bit of javascript doesn't make sense to me. Why are you taking c_value, adding c_value (which is nothing) to it, then adding the value from the form field and then adding a line break? Try this instead.

 

function post_value(){
var c_value = "";
for (var i=0; i < document.form1.select_contact.length; i++) {
	if (document.form1.select_contact.checked) {
		c_value = document.form1.select_contact.value;
	}
}
opener.document.form.sendto.value=c_value;
self.close();
}

 

I hope that helps.

Take care.

Link to comment
Share on other sites

Thanks for your reply! =] Really appreciate it.

It didn't work as well. I think it's at the javascript part.

 

It works when I use the code below: ( I do  not know how you embed the script =}  )

This script doesn't work after the filtering. The one you gave to me only allow user to select one checkbox, but it doesn't work after the filtering too. The reason why i put a new line break at the end because all the values selected (which may be more than one checkbox value) will be pass to a textarea at the parent window.

 

Any advise ? Thanks !

 

function post_value(){

var c_value = "";

for (var i=0; i < document.form1.select_contact.length; i++)

  {

  if (document.form1.select_contact.checked)

      {

      c_value = c_value + document.form1.select_contact.value + "\n";

      }

  }

  opener.document.form.sendto.value=c_value;

  self.close();

}

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.