FP said the following on 7/20/2006 5:36 PM:
> Randy Webb wrote:
>> FP said the following on 7/20/2006 4:26 PM:
>>> This should be simple but I just can't seem to figure it out.
>>> I have a form with 2 checkboxes in it. Clicking either checkbox runs a
>>> js function which opens a new window. The form targets that new
>>> window.
>> Hmmm. And if you just submit the form, guess what happens?
>> Yeah, it opens the window for you, gives it the name, and even passes
>> the form information.
>
> Alright, I suppose I should have clarified that the new window closes
> itself again afterwards and I don't want the window that you're
> origionally in to disappear or reload.
And it will still do that if you just submit the form and have the
loading page close itself. But life is simpler than that.
> I know you've already told me to do this with iFrames but after
> spending an hour trying to figure out how to make that work I
> figured I'll stick with my clunky way of displaying a new window
> and having it run the required PHP code.
If your only need is to have a PHP script execute, you don't need the
IFrame or the new window. You only need them if you want some return
value from the PHP code.
>>> How can I pass a hidden value letting the new window know which
>>> checkbox was clicked?
>> Change the method of your form and get it from the querystring.
>> Or, have the PHP file return it into the page.
>
> When you say "Change the method of your form and get it from the
> querystring" are you saying I should add which checkbox was clicked as
> part of the URL?
No, change the method from post to get and the browser will
automatically add it to the URL. But, have the PHP code read the
submitted form data. Your checkbox and hidden field values will be
available to it.
> Since both checkboxes submit the same form and call the same JS
> function I don't know how to add which checkbox was clicked as part of
> the information that is transfered to the processing page.
The browser does it for you. Try it. The PHP page will have access to
the checked checkbox.
>
>>> Below is the code I'm currently using:
>>>
>>> function JSCheckbox(WhichForm) {
>>> window.open('', "CheckboxWindow", 'height=1,width=1');
>>> document.getElementById(WhichForm).submit();
>>> }
>> And I suppose you get a 1x1 window?
>
> IE 5.2 on the Mac does, Safari & Netscape don't.
Nor any browser on a PC. The smallest window I recall being able to open
on a PC was 100x100 or so.
>>> <form id="FormCheckbox1" method="post" action="checkbox.php"
>>> target="CheckboxWindow">
>>> <input type="hidden" name="TheRecID" value="1">
>>> <input type=checkbox NAME="FlagDone" VALUE="1"
>>> onclick="JSCheckbox('FormCheckbox1');">
>>> .... second checkbox
>>> </form>
>> That is a ridiculously dumb way to try to open a new window and target a
>> form to it. Sorry for the blunt response but it is.
>
> I don't mind the blunt response, after 20 hours of playing with
> javascript I don't know any better; what would be more helpfull is the
> correct way to do this.
Fair enough.
> So how would you do the following;
> - the processing has to take place in a new window without
> disrupting the current window
Actually, it doesn't. You can do it in the same window without
disrupting it.
> - the processing window has to know what checkbox was clicked
It does if the form is submitted.
> - there are other hidden fields that are passed
If you are not getting a return value from the PHP code, you can simply
set the .src of an Image Object to the string you need.
"How do I run a server side script?"
<URL: http://jibbering.com/faq/#FAQ4_34>
<iframe name="myIFrame" style="width:0px;height:1px;"></iframe>
target="window.frames['myIFrame']"
And submit your form....
--
Randy
comp.lang.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly
Temporarily at:
http://members.aol.com/_ht_a/hikksnotathome/cljfaq/
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/