I'm having a for where I can create invoices. Now I'm having the form fields where I have to fill it out with the customer's data. Well I don't want to fill out existing customer's data everytime. So I am having a link which opens up a page with a list of all existing customers. Now how can I get it to auto complete the form fields when clicking on the customer in the popup page? In other words, when clicking on a customer in the popup page, the form fields have to be auto-completed in the parent page.

I'm having a for where I can create invoices. Now I'm having the form fields where I have to fill it out with the customer's data. Well I don't want to fill out existing customer's data everytime. So I am having a link which opens up a page with a list of all existing customers. Now how can I get it to auto complete the form fields when clicking on the customer in the popup page? In other words, when clicking on a customer in the popup page, the form fields have to be auto-completed in the parent page.

You are being way too vague here, why don't you post what you have done so far and maybe someone might be able to help you.

k ;-)

Will do

Member Avatar for langsor

I think I know what you're talking about ...
The link you open is a new window and you have selections in that window ... when you click on a selection you want to populate the original (main) window form fields ...

If this is what you mean, then try something like this example
main.html

<html>
<head>
<script type="text/javascript">
// open your pop-up window ...
var pup = window.open('pup.html','pup');

function populate_form ( val1, val2 ) {
  var form = document.getElementById('my_form');
  for ( var i = 0; i < form.elements.length; i ++ ) {
    var element = form.elements.item(i);
    switch ( element.name ) {
      case 'field_1': element.value = val1; break;
      case 'field_2': element.value = val2; break;
    }
  }
}

</script>
</head>
<body>
<form id="my_form">
  <input type="text" name="field_1" />
  <input type="text" name="field_2" />
</form>
</body>
</html>

pup.html

<html>
<head>
<script type="text/javascript">
function send_to_parent ( target ) {
  var val1 = target.getAttribute('val1');
  var val2 = target.getAttribute('val2');
  opener.populate_form( val1, val2 );
  return false;
}
</script>
</head>
<body>
<a href="javascript:" val1="one" val2="two" onClick="send_to_parent(this)">Populate 'one','two'</a><br />
<a href="javascript:" val1="three" val2="four" onClick="send_to_parent(this)">Populate 'three','four'</a>
</body>
</html>

If this is not what you mean, then please clarify ...

Thanks

[edit]
Only problem is, this is all javascript ... doing this in PHP is another matter ... one minute
[/edit]

:-\

Member Avatar for langsor

In PHP you would have to submit the child window with the parent window as the form action ...

<form aciton='parent.php" method="POST">

... and grab the submitted child form values in the parent window ...

<?php 
$val1 = $_POST['val1'];
?>

... thus reloading the parent page, and insert the values in the parent window form like this ...

<input type="text" name="val1" value="<? print $val1; ?>" />

The child window would be a form with multiple, probably <input type="hidden" ...> values for each person you wanted to submit the values for.

Hope this helps

[edit]
I would do it with JavaScript personally, since it's for you and you know JS is supported.
[/edit]

Hey.

This is exactly what I was looking for.

Thanx so much.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.