By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,128 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

Input checkbox

P: n/a
Hi. I got a checkbox in a form. When the form is submitted, an email
is generated. In the email text is the field name: on or off. The
client doesn't want to see on or off, but yes or no. Question. Before
I submit the form, is it possible to change the input from checkbox to
text? If it was checked, have the value Yes, otherwise No?
Oct 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"Dennis Allen" <de****@dennisallen.com> wrote in message
news:11*************@corp.supernews.com...
Hi. I got a checkbox in a form. When the form is submitted, an email
is generated. In the email text is the field name: on or off. The
client doesn't want to see on or off, but yes or no. Question. Before
I submit the form, is it possible to change the input from checkbox to
text? If it was checked, have the value Yes, otherwise No?

Will this help? Watch for word-wrap.

<html>
<head>
<title>yes_no.htm</title>
<script type="text/javascript">
function submits(form) {
for (var i=0; i<form.length; i++) {
if (form.elements[i].type == "checkbox") {
var b = form.elements[i].name;
if (form.elements[i].checked) {
document.getElementById(b+"_").value = "Yes";
} else {
document.getElementById(b+"_").value = "No";
}
form.elements[i].disabled = true;
}
}
return false;
}
</script>
</head>
<body>
<form action="" method="post" onsubmit="return submits(this)">
<input type="text" name="box1_" id="box1_">
<input type="checkbox" name="box1" id="box1">
<input type="text" name="box2_" id="box2_">
<input type="checkbox" name="box2" id="box2" checked>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Change "return false;" to "return true;".
Change "text" to "hidden" re "<input type=".

Disabled form elements are not passed.
Here's an ASP version that displays the results:

<%@ Language="VBScript" %>
<% For Each e in Request.Form
Response.Write("<br>" & e & " : " & Request.Form(e))
Next
%>
<html>
<head>
<title>yes_no.asp</title>
<script type="text/javascript">
function submits(form) {
for (var i=0; i<form.length; i++) {
if (form.elements[i].type == "checkbox") {
var b = form.elements[i].name;
if (form.elements[i].checked) {
document.getElementById(b+"_").value = "Yes";
} else {
document.getElementById(b+"_").value = "No";
}
form.elements[i].disabled = true;
}
}
return true;
}
</script>
</head>
<body>
<form action="" method="post" onsubmit="return submits(this)">
<input type="hidden" name="box1_" id="box1_">
<input type="checkbox" name="box1" id="box1">
<input type="hidden" name="box2_" id="box2_">
<input type="checkbox" name="box2" id="box2" checked>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Oct 13 '05 #2

P: n/a
Dennis Allen said the following on 10/12/2005 10:58 PM:
Hi. I got a checkbox in a form. When the form is submitted, an email
is generated. In the email text is the field name: on or off. The
client doesn't want to see on or off, but yes or no. Question. Before
I submit the form, is it possible to change the input from checkbox to
text? If it was checked, have the value Yes, otherwise No?


Have the server change it when the email is generated.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 13 '05 #3

P: n/a
Thanks for the reply. Yes, I could do that. But all the input fields
go out on the email. I want to avoid having [confirm:on] altogether and
just have [confirm:yes].

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:4d******************************@comcast.com. ..
"Dennis Allen" <de****@dennisallen.com> wrote in message
news:11*************@corp.supernews.com...
Hi. I got a checkbox in a form. When the form is submitted, an
email
is generated. In the email text is the field name: on or off. The
client doesn't want to see on or off, but yes or no. Question.
Before
I submit the form, is it possible to change the input from checkbox
to
text? If it was checked, have the value Yes, otherwise No?

Will this help? Watch for word-wrap.

<html>
<head>
<title>yes_no.htm</title>
<script type="text/javascript">
function submits(form) {
for (var i=0; i<form.length; i++) {
if (form.elements[i].type == "checkbox") {
var b = form.elements[i].name;
if (form.elements[i].checked) {
document.getElementById(b+"_").value = "Yes";
} else {
document.getElementById(b+"_").value = "No";
}
form.elements[i].disabled = true;
}
}
return false;
}
</script>
</head>
<body>
<form action="" method="post" onsubmit="return submits(this)">
<input type="text" name="box1_" id="box1_">
<input type="checkbox" name="box1" id="box1">
<input type="text" name="box2_" id="box2_">
<input type="checkbox" name="box2" id="box2" checked>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Change "return false;" to "return true;".
Change "text" to "hidden" re "<input type=".

Disabled form elements are not passed.
Here's an ASP version that displays the results:

<%@ Language="VBScript" %>
<% For Each e in Request.Form
Response.Write("<br>" & e & " : " & Request.Form(e))
Next
%>
<html>
<head>
<title>yes_no.asp</title>
<script type="text/javascript">
function submits(form) {
for (var i=0; i<form.length; i++) {
if (form.elements[i].type == "checkbox") {
var b = form.elements[i].name;
if (form.elements[i].checked) {
document.getElementById(b+"_").value = "Yes";
} else {
document.getElementById(b+"_").value = "No";
}
form.elements[i].disabled = true;
}
}
return true;
}
</script>
</head>
<body>
<form action="" method="post" onsubmit="return submits(this)">
<input type="hidden" name="box1_" id="box1_">
<input type="checkbox" name="box1" id="box1">
<input type="hidden" name="box2_" id="box2_">
<input type="checkbox" name="box2" id="box2" checked>
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Oct 13 '05 #4

P: n/a
This is online ordering with FrontPage Server Extensions. Once it is
submitted, I have no control.

"Randy Webb" <Hi************@aol.com> wrote in message
news:u7******************************@comcast.com. ..
Dennis Allen said the following on 10/12/2005 10:58 PM:
Hi. I got a checkbox in a form. When the form is submitted, an
email is generated. In the email text is the field name: on or off.
The client doesn't want to see on or off, but yes or no. Question.
Before I submit the form, is it possible to change the input from
checkbox to text? If it was checked, have the value Yes, otherwise
No?


Have the server change it when the email is generated.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly

Oct 13 '05 #5

P: n/a

"Dennis Allen" <de****@dennisallen.com> wrote in message
news:11*************@corp.supernews.com...
Thanks for the reply. Yes, I could do that. But all the input fields go
out on the email. I want to avoid having [confirm:on] altogether and just
have [confirm:yes].


have two hidden text fields and have them submitted in the form and the text
box ignored.
Oct 13 '05 #6

P: n/a
Lee
Dennis Allen said:

Thanks for the reply. Yes, I could do that. But all the input fields
go out on the email. I want to avoid having [confirm:on] altogether and
just have [confirm:yes].


Just about any solution is going to introduce more sources of error than it is
worth and make the site unusable by people with Javascript disabled.
How about changing the control from a checkbox to a Select:

<select name="confirm">
<option value="Yes" selected>Yes</option>
<option value="No">No</option>
</select>

Oct 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.