473,499 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Submitting info with JS

FP
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.
How can I pass a hidden value letting the new window know which
checkbox was clicked?
Below is the code I'm currently using:

function JSCheckbox(WhichForm) {
window.open('', "CheckboxWindow", 'height=1,width=1');
document.getElementById(WhichForm).submit();
}
<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>

Jul 20 '06 #1
7 1664
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.
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.
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?
<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.

--
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/
Jul 20 '06 #2
FP
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. 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.
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?
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.

>
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.

>
<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.
So how would you do the following;
- the processing has to take place in a new window without
disrupting the current window
- the processing window has to know what checkbox was clicked
- there are other hidden fields that are passed

Jul 20 '06 #3
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/
Jul 21 '06 #4
FP
Randy,
I assume there is something very basic I'm not understanding here.
Previously I had 2 forms;
- 1 form for checkbox Done
- 1 form for checkbox Monitor

Both forms called the same HTML page and submitted the hidden value
"RecID" and "CheckboxClicked", however CheckboxClicked had either the
value "Done" or "Monitor".

These forms were submitted to an html page which just had the PHP code:
....
if($_REQUEST['CheckboxClicked']=='Done'){
//toggle database value for flagdone
}else{
//toggle database value for flagmonitor
}
I'm trying to put both checkboxes in the same form because display wise
they're not lining up in older browsers. The problem is:
I don't know how to set "CheckboxClicked" to "Done" or "Monitor"
depending on the checkbox the user clicked on.
Or if I have to have each checkbox call a different javascript
functions then I don't know how to set "CheckboxClicked" from within
the javascript function.

If either of the above 2 is possible, could you please write out the
code that will do that.
Thanks in advance.

Jul 21 '06 #5
FP said the following on 7/20/2006 11:34 PM:
Randy,
I assume there is something very basic I'm not understanding here.
Yes, there is.
Previously I had 2 forms;
- 1 form for checkbox Done
- 1 form for checkbox Monitor

Both forms called the same HTML page and submitted the hidden value
"RecID" and "CheckboxClicked", however CheckboxClicked had either the
value "Done" or "Monitor".

These forms were submitted to an html page which just had the PHP code:
....
if($_REQUEST['CheckboxClicked']=='Done'){
//toggle database value for flagdone
}else{
//toggle database value for flagmonitor
}
OK, simple enough.
I'm trying to put both checkboxes in the same form because display wise
they're not lining up in older browsers. The problem is:
I don't know how to set "CheckboxClicked" to "Done" or "Monitor"
depending on the checkbox the user clicked on.
<input type="checkbox" name="CheckboxClicked" value="Done">
<input type="checkbox" name="CheckboxClicked" value="Monitor">

Now, when the form gets submitted, PHP will read the value of
CheckboxClicked and act accordingly. And, you don't even have to submit
the form to trigger the PHP script.
Or if I have to have each checkbox call a different javascript
functions then I don't know how to set "CheckboxClicked" from within
the javascript function.
Neither.
If either of the above 2 is possible, could you please write out the
code that will do that.
The first is simple, the second is like using a sledgehammer to drive a
finishing nail in. Its overkill.
What you want to do is this simple:

function runPHPScript(radioButton){
//code below copied from the FAQ and modified
var dummyImage = new Image();
dummyImage.src="scriptURL.php?"+radioButton.name+' ='+radioButton.value;
//replace scriptURL.php with the path to your php script
}

<input type="radio" name="CheckboxClicked" value="Done"
onclick="runPHPScript(this)">
<input type="radio" name="CheckboxClicked" value="Monitor"
onclick="runPHPScript(this)">

I will let you ponder on why I changed them to radio buttons instead of
checkboxes (It works the same with either though).
--
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/
Jul 21 '06 #6
FP
Randy Webb wrote:
<input type="checkbox" name="CheckboxClicked" value="Done">
<input type="checkbox" name="CheckboxClicked" value="Monitor">
In the results page I was trying to figure out which checkbox was
clicked and update only it, now it finally occurred to me that it
doesn't matter which one was clicked, just update both. That was a
very stupid mistake and I understand why you didn't get the question I
was trying to ask.

Now, when the form gets submitted, PHP will read the value of
CheckboxClicked and act accordingly. And, you don't even have to submit
the form to trigger the PHP script.
I'm also new to PHP so I don't want to get into PHP scripts at this
point.

I will let you ponder on why I changed them to radio buttons instead of
checkboxes (It works the same with either though).
FlagDone is suppose to be completely independant of FlagMonitor, but I
see why you said that.

You had said in a different post that I was submitting the data in a
bad way by having a function open a new window and posting into it from
the form. I tried to modify my code and currently have;
<form method="post" action="donemonitor.php" target="WinDoneMonitor"
onsubmit="window.open('donemonitor.php', 'WinDoneMonitor', 'height=100
width=100');">
This works, new window opens, record is updated, window closes itself.
Only the height & width is not respected, how do I make that work?

Thanks again for your help so far.

Jul 21 '06 #7
FP said the following on 7/21/2006 2:28 PM:
Randy Webb wrote:
<snip>
>Now, when the form gets submitted, PHP will read the value of
CheckboxClicked and act accordingly. And, you don't even have to submit
the form to trigger the PHP script.

I'm also new to PHP so I don't want to get into PHP scripts at this
point.
Ya gotta start somewhere, may as well be here.
>I will let you ponder on why I changed them to radio buttons instead of
checkboxes (It works the same with either though).

FlagDone is suppose to be completely independant of FlagMonitor, but I
see why you said that.
Change them to checkboxes, give them different names, and test the code....
You had said in a different post that I was submitting the data in a
bad way by having a function open a new window and posting into it from
the form.
Yes, because its a bad way to do it.
I tried to modify my code and currently have;
<form method="post" action="donemonitor.php" target="WinDoneMonitor"
onsubmit="window.open('donemonitor.php', 'WinDoneMonitor', 'height=100
width=100');">
This works, new window opens, record is updated, window closes itself.
It "works" only if the window.open call is honored. It may not be,
depending on the popup blocker.
Only the height & width is not respected, how do I make that work?
Use the code I gave you, test it, then stop trying to open a new window
and the height and width won't matter.

--
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/
Jul 21 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2118
by: jason | last post by:
Hello and Good day. There's a site I want to link to passing info I collect without having to re-enter the data on that's sites input form. I know this is not always possible, but in this case...
5
1883
by: Don | last post by:
I have a need to submit a form, but don't need the user to click on a button. How do I do this? Is there some way, using JavaScript, to setup a <form> tag to do this? Thanks, Don ----==...
3
1147
by: Manfred Bauer | last post by:
Dear all, I have written an ASP.NET application using NT-Authentfication against an Active Directory domain. Users that are logged on have access to an Outlook Web Access site, also using...
2
4625
by: Syam | last post by:
Hello everyone, I am just barely two months old into learning asp.net and vb.net. Currently I am working on a project to store customer database. I have a question about creating a preview page:...
3
1431
by: Barkster | last post by:
I registered for this service and when I put my username it looked up the username without submitting and told me it was taken after leaving the field. Any ideas on how they are doing it...
2
3808
by: varun | last post by:
Hi, I am using goahead webserver...i have a form, in acction attribute i am calling a c function.. after submitting the form i need to close the window and i need to reload the window which...
16
2834
by: browntown | last post by:
so I have this application I'm nearly finished with. The only thing the client has requested is the ability to submit the form by pressing "enter". I didn't think this would be a huge pain in the...
3
1550
by: veronicab | last post by:
Hi all, I have a page with a very large form. When user clicks on the button to submit the form, page "freezes" for several seconds, and then finally you notice it was not frozen but just...
1
1601
by: asp beginner | last post by:
I am building an Eccomerce site and I am trying to make my shopping cart work. I am having a problem with when I have entered data into my form it is not submitting into my access database. This my...
0
7131
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6894
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7388
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5470
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4600
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3091
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.