i want to create a form that when an option in the list box is chosen, it automatically pop out a new window which then allow me to enter certain information in the new pop up window then pass the information back to the default form?
when i choose ADD NEW, a new window pop-up, and allow me to enter "2", then the pop-up window closed, pass the value back to the original page. when REFRESH option is chosen then the page will refresh! this time the <SELECT> will become
Well, here is an example that will allow the client window to communicate with the parent window:
Code:
<html>
<head>
<title>Parent window</title>
<script type="text/javascript">
function open_win(){
win = window.open();
win.document.write("<html><head><title>Enter value</title></head><body>The value you enter here will go back into the parent window:<br><form><input type=\"text\" name=\"thevalue\"><input type=\"button\" value=\"Send Data\" onclick=\"window.opener.form1.changevalue.value=document.forms[0].thevalue.value; window.close();\"</form></body></html>");
}
</script>
</head>
<body>
<form name="form1" action="wherever.php" method="post">
<input type="text" name="changevalue"><br>
<input type="button" onclick="open_win();" value="Open Window">
</form>
</body>
</html>
But you are talking about a lot more than this... I doubt anyone is going to make this entire script for you for free...
OK - going to bed now. I'll get something for you tomorrow
morning (hopefully thats OK).
I'll make it so...
1) A new popup is shown when the "ADD NEW" option is
selected.
2) The popup will show two textfields for entry.
3) The popup will also include a CLOSE button.
4) The results will be returned in "hidden" objects in the
"parent" window when this, the Close button, is pressed.
Originally posted by olerag Adam is faster than me and given an example to
communicate from the "child" back to the "parent"
window.
I've been working with code long enough it's about as fast as talking now.
Also, this is obviously not exactly what they wanted, but what they wanted I wasn't going to make for free. I'm hoping that they can look at this and figure out how to do the rest...
Here you go. I made the "parent" items that receive the
input "text" items instead of "hiddens" so you can see the
results. You can alter the items as you like.
PHP Code:
<html>
<head>
<script type="text/javascript">
function showResults(name, output1, output2) {
var listObj = document.myForm.selectList1;
var newWin;
var val;
for (var i=0; i<listObj.length; i++) {
if (listObj.options[i].selected) {
val = listObj.options[i].value;
if (val.toLowerCase() == "addnew") {
newWin = window.open('','','top=150,left=150,width=325,height=300');
if (!newWin.opener) {
newWin.opener = self;
}
with (newWin.document) {
open();
write('<html>');
write('<body onLoad="document.form.box1.focus()"><form name=form>' + '<br>');
write('<p>You may enter your ' + name + ' here and it will be copied into the form for you.');
write('<p><center>' + 'Entry 1' + ': <input type=text name=box1 size=25 onKeyUp=' + output1 + '=this.value>');
write('<p><center>' + 'Entry 2' + ': <input type=text name=box2 size=15 onKeyUp=' + output2 + '=this.value>');
write('<p><input type=button value="Click to close when finished" onClick=window.close()>');
write('</center></form></body></html>');
close();
}
}
}
}
}
</script>
i didn't set the size for the select. so once i choose ADD NEW, the window pop up i fill in the form, close the window. The select option will remain at the add new option. if i want to choose other option e.g. refresh! the window pop up again!
because of the OnClick command!..
i try to set <selected = "selected" on other options but it doesn't work also....
emm other options won't bring me the pop-up window ..
emm first i set the SELECT with no size ( the one you show me is Size=5)
so when i run the script everything is great! a LIST BOX appear, i press the arrow button to choose ADD NEW in the list box.. the window pop up then i can enter what ever i want!.. then i click the CLOSE WINDOW BUTTON and back to parent window ..
problem occurs when i get back to parent window
at the parent window... at the listbox, i want to choose another option , but the ADD NEW somehow become the default option for the LIstBox..i can't press the arrow button to go for other option. because once i press the button the add new window pop up again..
I've run this in IE6 and NN7 and do not get the affect that
you are. And it doesn't matter if the selection size
parameter is set at 1 or 5. The popup only appears when
the "Add New" is actually selected.
Bookmarks