Hi,
I am trying to change and pass the value of a hidden input type on a
form tag to a cgi processing script based on the value of a checkbox
within the form:
function CheckBoxes () {
if (document.MyFor m.CheckBox1.che cked) {
document.MyForm .recipient.valu e = "2";
document.MyForm .submit();
}
}
...
<form name="MyForm" action="http://www.mycompany.c om/cgi/MailMyForm.pl"
method="post" onSubmit="retur n CheckBoxes()">
<input type="hidden" name="recipient " value="1">
<input name="CheckBox1 " type="checkbox" value="yes">
...
</form>
Obviously, this is a simplified version of the real example.
The "recipient" value of "1" is a default recipient's e-mail address in
case no checkboxes are selected. If (in this case) the checkbox
"CheckBox1" is checked, then "recipient" should get set to a value of
"2" which the cgi script will recognize as a different e-mail address
and process the form accordingly (it would just go to the e-mail
address defined in the cgi script for a "recipient" value of "2").
Any idea why this won't work? Is it that I cannot change the value of
"recipient" ?
Any help is appreciated. 12 2172
Jim Tome wrote: function CheckBoxes () { if (document.MyFor m.CheckBox1.che cked) { document.MyForm .recipient.valu e = "2"; document.MyForm .submit(); } } ..
<form name="MyForm" action="http://www.mycompany.c om/cgi/MailMyForm.pl" method="post" onSubmit="retur n CheckBoxes()">
<input name="CheckBox1 " type="checkbox" value="yes"> .. </form>
Why not get rid of the function, and use the onclick event handler of
the checkbox in its stead?
<form action="http://www.mycompany.c om/cgi/MailMyForm.pl"
method="post" >
<input type="hidden" name="recipient " value="1">
<input name="CheckBox1 " type="checkbox" value="yes"
onclick='recipi ent.value=this. checked?"2":"1" '>
However you need to be certain that the user has javascript enabled.
Mick
On Thu, 06 May 2004 15:19:23 GMT, Mick White
<mw******@BOGUS rochester.rr.co m> wrote:
[snip] <input name="CheckBox1 " type="checkbox" value="yes" onclick='recipi ent.value=this. checked?"2":"1" '>
That won't work in most browsers. Remember that using ids and names as
global identifiers is a Microsoft-ism that isn't standardised, and
certainly not copied in all cases.
onclick="this.f orm.elements['recipient'].value=this.che cked?'2':'1'"
Probably best in a function.
Mike
--
Michael Winter M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Yes, thank for your suggestion. My next question is, suppose there are
three checkboxes (any or all of which can be selected). Checking a
checkbox indicates that a copy of the form's submission get e-mailed to
a separate recipient depending on the checkbox checked (so, in this
simple example, the form would e-mail to one, two or three people).
How can I test and handle this?
Thanks again for your help ? sometime I get too close to these things
to see the simple solution!
On 2004-05-06 10:19:23 -0500, Mick White <mw******@BOGUS rochester.rr.co m> said: Jim Tome wrote:
function CheckBoxes () { if (document.MyFor m.CheckBox1.che cked) { document.MyForm .recipient.valu e = "2"; document.MyForm .submit(); } } ..
<form name="MyForm" action="http://www.mycompany.c om/cgi/MailMyForm.pl" method="post" onSubmit="retur n CheckBoxes()">
<input name="CheckBox1 " type="checkbox" value="yes"> .. </form>
Why not get rid of the function, and use the onclick event handler of the checkbox in its stead?
<form action="http://www.mycompany.c om/cgi/MailMyForm.pl" method="post" > <input type="hidden" name="recipient " value="1"> <input name="CheckBox1 " type="checkbox" value="yes" onclick='recipi ent.value=this. checked?"2":"1" '>
However you need to be certain that the user has javascript enabled. Mick
Michael Winter wrote: On Thu, 06 May 2004 15:19:23 GMT, Mick White <mw******@BOGUS rochester.rr.co m> wrote:
[snip]
<input name="CheckBox1 " type="checkbox" value="yes" onclick='recipi ent.value=this. checked?"2":"1" '>
That won't work in most browsers. Remember that using ids and names as global identifiers is a Microsoft-ism that isn't standardised, and certainly not copied in all cases.
onclick="this.f orm.elements['recipient'].value=this.che cked?'2':'1'"
Probably best in a function.
Mike
Yes, proper, unambiguous, references are important. I should note that.
I am not sure which browsers would fail. None of my current crop, each
is tolerant of my miscoding!!.
For a one-off, I wouldn't create a function. Your points are well taken,
though.
Mick
On Thu, 06 May 2004 16:07:47 GMT, Mick White
<mw******@BOGUS rochester.rr.co m> wrote: Michael Winter wrote:
On Thu, 06 May 2004 15:19:23 GMT, Mick White <mw******@BOGUS rochester.rr.co m> wrote:
[snip]
<input name="CheckBox1 " type="checkbox" value="yes" onclick='recipi ent.value=this. checked?"2":"1" '>
[snip]
I am not sure which browsers would fail. None of my current crop, each is tolerant of my miscoding!!.
All Mozilla-based browsers will fail with unqualified references like the
above.
Mike
--
Michael Winter M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply) On Thu, 06 May 2004 16:07:47 GMT, Mick White <mw******@BOGUS rochester.rr.co m> wrote:
[snip]
<input name="CheckBox1 " type="checkbox" value="yes" onclick='recipi ent.value=this. checked?"2":"1" '>
[snip]
Michael Winter wrote: All Mozilla-based browsers will fail with unqualified references like the above.
Mike http://www.mickweb.com/demo/formRef.html
Not to belabour the point, but it works in Netscape 7, IE 5.2, Safari
1.1 and Firefox 1.8 (All Mac)
I'm not which of these browsers are Mozilla based or not.
Mick
Michael Winter wrote: On Thu, 06 May 2004 16:07:47 GMT, Mick White <mw******@BOGUS rochester.rr.co m> wrote:
Michael Winter wrote:
On Thu, 06 May 2004 15:19:23 GMT, Mick White <mw******@BOGUS rochester.rr.co m> wrote:
[snip]
<input name="CheckBox1 " type="checkbox" value="yes" onclick='recipi ent.value=this. checked?"2":"1" '>
[snip]
I am not sure which browsers would fail. None of my current crop, each is tolerant of my miscoding!!.
All Mozilla-based browsers will fail with unqualified references like the above.
Mike
For some reason the code in a form element event handler executes in the
context (or namespace or whatever you want to call it) of the container form,
as a result:
<form>
<input type="text" name="recipient ">
<input name="CheckBox1 " type="checkbox"
value="yes" onclick="recipi ent.value=this. checked?2:1">
</form>
works just fine in Firefox 0.8, Netscape 4.78 and Opera 7.23. I recall a
discussion about this some time ago (don't have time to google for it right
now) and it seems to me that this is in fact documented behaviour and can be
relied on. Of course there are a large number of reasons to fully qualify the
reference, just pointing out that it isn't actually necessary in this case.
--
| Grant Wagner <gw*****@agrico reunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
* http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
* http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
On Thu, 06 May 2004 19:34:29 GMT, Grant Wagner
<gw*****@agrico reunited.com> wrote:
[snip] For some reason the code in a form element event handler executes in the context (or namespace or whatever you want to call it) of the container form, as a result:
<form> <input type="text" name="recipient "> <input name="CheckBox1 " type="checkbox" value="yes" onclick="recipi ent.value=this. checked?2:1"> </form>
works just fine in Firefox 0.8, Netscape 4.78 and Opera 7.23. I recall a discussion about this some time ago (don't have time to google for it right now) and it seems to me that this is in fact documented behaviour and can be relied on. Of course there are a large number of reasons to fully qualify the reference, just pointing out that it isn't actually necessary in this case.
I can't find any documentation to support this, nor can I think of any
reason why it should be so. In fact, both Netscape and Microsoft state
that you should either use the name of the element or the elements
collection in conjunction with the form name or the forms collection (they
don't mention named look-ups with the collections):
myForm.myInput
myForm.elements[0]
Of course, only the latter, in conjunction with the forms collection not
the form name, is standardised.
Mike
--
Michael Winter M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
On Thu, 06 May 2004 18:56:01 GMT, Mick White
<mw******@BOGUS rochester.rr.co m> wrote:
[unqualified reference from inside a form] Not to belabour the point, but it works in Netscape 7, IE 5.2, Safari 1.1 and Firefox 1.8 (All Mac)
True, but why not use the method that is more likely to work? Moreover, a
fully qualified reference documents itself.
I tested the success of unqualified controls accesses from outside of the
form. The tests involve whether the control is inside a form (F) and if a
name (N) or id (I) is used. The success (S) is qualified by browser.
F I N S
n y n IE, Opera
n n y IE, Opera
y y n -none-
y n y -none-
Mozilla 1.8a and NN4 failed all four. Strangly, Microsoft's documentation
state that the third (an id'd control inside a form) should work, yet it
doesn't. From inside a form:
I N S
y n IE, Opera, Mozilla
n y IE, Opera, Mozilla, NN4
Using a fully qualified reference works in all cases, except in NN4 when
the control or form uses an id exclusively.
I'm not which of these browsers are Mozilla based or not.
Only Netscape, as far as I'm aware, though Firefox (don't you mean 0.8?)
is Mozilla Firefox.
Mike
--
Michael Winter M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jim |
last post by:
I have a 2 checkboxes and a hidden field..what I want to happen is
that you can only click on 1 of these checkboxes at a time and when
you check a checkbox it will assign the hidden field "txtreferral" a
value and when you uncheck the checkbox it will set the hidden field
value back to nothing ..I have the clicking on 1 check box at a time
down but when I try to add the code to assign the value to the hidden
field I get an error in the...
|
by: David Groom |
last post by:
I have a form which contains amongst other code:
<form action="" name="diagform" id="diagform">
<input name="answer" type="hidden" id="q1" value="">
<input name="answer" type="hidden" id="q2" value="">
<input name="answer" type="hidden" id="q3" value="">
........
<input name="answer" type="hidden" id="q9" value="">
<form>
|
by: Rob Meade |
last post by:
Hi all,
I have a loop in my code which builds the controls on the page.
I at one stage need to add some hidden input controls dynamically, I have
achieved this, and I have set their properties, however, there seems to be
one that I cannot set - ie, Name..
My code looks like this:
|
by: rob c |
last post by:
Hi
I'm not sure if this is the right place to ask for help on forms and radio
buttons...
In the following form, I'd like to set the value of 'item_name' based on which
radio button was selected.
If amount=14, then I want to set item_name='5x7 print'.
If amount=20, then I want to set item_name='5x7 print (drymounted)'.
|
by: laredotornado |
last post by:
Hi,
I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed
using Apache's apxs and the php library was installed to
/usr/local/php. However, when I set my "error_reporting" setting to be
"E_ALL", notices are still not getting reported. The perms on my file
are 664, with owner root and group root. The php.ini file is located
at /usr/local/lib/php/php.ini. Any ideas why the setting does not seem
to be having an effect? ...
| |
by: TopherB |
last post by:
Hi,
First let me say that my knowledge of HTML and Javascript is fairly limited. But I am stuck in a situation of trying to adapt a website's shopping cart to a new one.
Here's the problem, the code contains thousands of 'Add to Cart' buttons that look almost identical to this HTML snippet spread across over hundred pages:
<form>
<p align="center">
<select name="package" size="1" style="width: 170" style="font-weight: 700">
<option...
|
by: bmallett |
last post by:
First off, i would like to thank everyone for any and all help with this. That being said, I am having a problem retrieving/posting my dynamic form data. I have a form that has multiple options within options. I have everything being dynamically named from the previously dynamically named element. (I hope this makes sense.) I am not able to retrieve any of the dynamically created values. I can view them on the source page but can't pull them...
|
by: corykendall |
last post by:
Here is my code:
...
Setting hidden input to: <dsp:valueof param="tabname"/>
<input name="tabname" type="hidden" value='<dsp:valueof param="tabname"/>'/>
</dsp:form>
hidden input set to:<script language="JavaScript"> document.write(document.getElementById("tab_switchRefreshForm").elements.tabname.value);</script><BR/>
Now when I'm in IE, everything works fine and the output is as follows:
|
by: Dave Rado |
last post by:
Hi
I have been the following code by Freefind to use on my search page:
<form action="http://search.freefind.com/find.html" method="get"
accept-charset="utf-8" target="_self">
<input type="hidden" name="id" value="">
<input type="hidden" name="pageid" value="r">
<input type="hidden" name="mode" value="all">
<input type="hidden" name="n" value="0">
|
by: JCCDevel |
last post by:
Hi All,
I'm not too proficient in Javascript but am trying to help a friend
out. Bascially, the page we are having trouble with is loaded with a
numerical value in the url string. Example:
http://www.webpage.com/v4/payment_pg.php?FeeCalcTotalDecimal%20=49.50
I then parse the string to get the total. I then want to assign the
value to a hidden form value
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |