Click to See Complete Forum and Search --> : Updating textbox in childwindow through a select- and checkbox in parent


Shambler
10-16-2003, 11:30 AM
Hi there!

Nice looking forum you've got here :cool:

Ok, so I have a form which looks like this: http://www.geocities.com/dellep03/form.jpg (~29 kb) (not parsed as URL on purpose, since geocities doesn't allow linking to files - you have to copy/paste the url manually :( )

The idea is that you tick one or both of the checkboxes on the left, after which the selectionboxes gets enabled. Here you can select a number of users that are going to use that module, i.e. number of licenses.

Whenever you tick a checkbox or a selection box, the total price in the text boxes indicated with the red arrows, are updated accordingly.

This works perfectly. All good.

However, I would like to have the two text boxes with the total prices moved to (and updated in the same manner) a new window. (The reason for this, is that we have a LOT of modules, which would make the table very long/high and I figured it would be annoying to have to scroll to the very bottom of the page every time you want to see the total price. (There's no room on the sides of the table either)) This new window should open whenever any checkbox in the table is ticked.

I believe I should use the "Parent / child"-window setup, but I can't really figure out how to integrate it with the above. I have google'd for existing solutions and couldn't really find anything helpful :o .

I can post the code for my script if you like, but I figured my post was long enough already ;)

Hope you can picture what I'm babbling about and give me a couple of hints :)

Thanks in advance :)

Jona
10-16-2003, 02:40 PM
function openWin(){
var newWin = window.open("","newWin","width=400,height=500,scrollbars=yes,menubar=no");
with(newWin.document){
writeln("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
writeln("<html lang=\"en-US\">");
writeln("<head><title>Module View</title>");
writeln("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
writeln("</head>");
writeln("<body>");
writeln("<form action=\"form_action.ext\" name=\"module_form\"><div>");
writeln("<input type=\"text\" value="+opener.document.forms[0].name_of_text_box.value+">");
writeln("</div></form>");
writeln("</body></html>");
}
}


This is untested code but should work, however if it does not, send the form value to the function, and use the name of that variable in the place of opener.document.forms[0].name_of_text_box.value.

[J]ona

Shambler
10-17-2003, 03:21 AM
Thanks for your reply :)

It works fine if you send the value of the textbox to the form as a parameter to the function :D

There's just a minor issue remaining: Every time you submit (in my existing script, that would be every time you tick a checkbox / select a number of userlicenses) a new textbox is created in the popup-window, instead of updating the one which is already there. How would I make it do that, with this setup?

I made a simple form, just to make sure that the rest of my script wasn't messing things up in any way.



<html>
<head><title>Testform</title>
<script language="javascript">
function openWin(price){
var newWin = window.open("","newWin","width=400,height=500,scrollbars=yes,menubar=no");
with(newWin.document){
writeln("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\">");
writeln("<html lang=\"en-US\">");
writeln("<head><title>Module View</title>");
writeln("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
writeln("</head>");
writeln("<body>");
writeln("<form action=\"form_action.ext\" name=\"module_form\"><div>");
writeln("<input type=\"text\" value="+price+">");
writeln("</div></form>");
writeln("</body></html>");
}
}
</script>
</head><body>
<form>
Total price: &nbsp;<input type="textbox" value="" name="totalprice"></input>
<input type="submit" value="Submit" onClick="openWin(totalprice.value)">
</form>
</body></html>



- Thanks :)

Jona
10-17-2003, 08:22 AM
if(newWin.open()){
// code to display the form
} else {
newWin.close(); // close the window
winOpen(price); // re-send the variable to the function to open a new window in the old one's place
}


[J]ona

Shambler
10-20-2003, 04:12 AM
Sry, but I can't really get it to work :(

Stripped down, the script looks as follows: (If I understood you correctly)



<html>
<head><title>Testform</title>
<script language="javascript">
function openWin(price){
var newWin = window.open("","newWin","width=250,height=150,scrollbars=yes,menubar=no");
if(newWin.open()) {
with(newWin.document) {
writeln("<b>Total price:</b>");
writeln("<form>");
writeln("<input type=\"text\" value="+price+">");
writeln("</form>");
}
}
else {
newWin.close();
openWin(price);
}
}
</script>
</head><body>
<form>
Total price: &nbsp;<input type="textbox" value="" name="totalprice"></input>
<input type="submit" value="Submit" onClick="openWin(totalprice.value)">
</form>
</body></html>



When I hit submit a new window is opened with a textbox, which contains the value you entered in the parent window. That's ok. But now it also opens another completely blank window, plus it still writes new textboxes in the child window, instead of updating the first textbox.

Anyone? :o