Forum Moderators: open
the file location.php creates the info I want and has a button to click to insert it into the location field.
That is as far as I have gotten in this. I want to be able to insert the info into the field (without reloading the "parent" window) and close the window that was created by the openLinkCreation function.
Thank you for your assistance,
Mike
Here is the form that I want to insert it into:
<form name="Admin" method="post" action="<?php echo $root_1 . "/administrator/index.php?act=menu&task=save&id=" . $mid; ?>">
<input type="location" name="location" onClick="openLinkCreation()" value="<?php echo $menudata['location']; ?>">
<input type="submit" name="Submit" value="Save">
</fieldset>
</form>
All of the php tags are used to pull information from the database so there is already data in the field. For some reason this code is not working and I am clueless on where that is. What am I doing wrong?
Thank you very much,
Mike
Two observations:
1. what is 'type="location"'? Even if that were a valid form field type, it would conflict with the reserved Javascript word location which is the document's . . . location. So do not use location for your form field names or id's.
2. Get in the habit of adding id's to your form elements. They can be the same as the name attribute with the exception of radio buttons.
<input type="text" name="loc" id="loc">
This allows you to refer to specific elements using document.getElementById() rather than document forms[form_name].fieldname, and is a lot easier to follow. All you have to remember is an id is unique, do not have two of the same ID's in a given document.
The basic premise is parent opens child window, parent is referred to as window.opener, and child can send data back to opener. one of many threads [webmasterworld.com] dealing with window.opener, with working examples.
once you open the new window, in that new window you need only to do something like this:
<input type="button" onClick = window.opener.document.getElementById('loc').value=document.getElementById('loc').value; return false; window.close();" value="Close Me">
... Where the new window also has a field "loc". "document.getElementByID . . ." refers to the current document (the pop up.) "window.opener.document.getElementById" refers to the parent window.
Of course, it would be best to move that code into a function the head of the document so the button code is not bloated, but you get the idea.
<script type="text/javascript">
var w = window.opener;
if ( w ) {
var wd = w.document;
wd.getElementById( 'loc' ).value = <?php echo $output; ?>
}else{alert(...) }
</script>
Here is the form that I want to insert it into:
<form name="Admin" method="post" action="<?php echo $root_1 . "/administrator/index.php?act=menu&task=save&id=" . $mid; ?>">
<input id="loc" name="loc" onClick="openLinkCreation()" value="<?php echo $menudata['location']; ?>">
<input type="submit" name="Submit" value="Save">
</fieldset>
</form>