Click to See Complete Forum and Search --> : automaticly changing a form value from something selected in an earlier opened window


TheRiddler
11-04-2003, 02:16 AM
Ok i have a few forms and i want to attach some sort of color chooser to it, the screen will open into a new window with the use of an url right next to the text box. The color chooser are a number of fields with checkboxes added to them that have the same name but different values and the screen closes when a submit is done.
How can i automaticly change the value of a textfield in the form(not the color chooser, without refreshing) to that what is selected on the color chooser?

Gollum
11-04-2003, 03:31 AM
Well, there are many ways. Here's one...

say for instance you have a textbox and a checkbox on your main form called text1 and check1 (it doesn't really matter what they are, the technique is the same).

When you 'submit' your popup form, instead of actually submitting the form, you can do something like this:

function submitColours()
{
// set the values in the main form (called theForm) in the parent window.
window.opener.document.theForm.text1.value = document.colourForm.text1.value; window.opener.document.theForm.check1.checked = document.colourForm.check1.checked;

// close this one
window.close();
}

...

<button onclick="submitColours();">Submit</button>

TheRiddler
11-04-2003, 03:52 AM
Do i copy the script to the first form or the color chooser, and do i need to go to the choose trough a submit or will a normal url will do fine?

Gollum
11-04-2003, 05:06 AM
Yes, this script goes in the popup colour chooser.
Instead of doing a normal submit, you do the code shown above. In fact you don't even need a <form> tag in your colour chooser as you are not sending anything to the server.