473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Setting a value to a hidden field

Jim
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 javascript console..heres my code so far:

The two checkboxes are named txtreferral1 and txtreferral2 here is the
code for txtreferral2....

onclick="if(txtreferral1.checked)txtreferral1.chec ked=!this.checked;txtreferral.value="EMPS""

thanks

-Jim
Jul 23 '05 #1
1 5552
Lee
Jim said:

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 javascript console..heres my code so far:

The two checkboxes are named txtreferral1 and txtreferral2 here is the
code for txtreferral2....

onclick="if(txtreferral1.checked)txtreferral1.che cked=!this.checked;txtreferral.value="EMPS""


1. What did the error message say?

2. Why use Javascript at all? Why not:
<input type="radio" name="txtreferral" value=""> None<br>
<input type="radio" name="txtreferral" value="OTHER"> Other<br>
<input type="radio" name="txtreferral" value="EMPS"> Emps<br>

3. Here's a very non-general solution:

Note that we don't care about the current state of the
other box or of the hidden value when a box is clicked.

<html>
<head>
<script type="text/javascript">
function boxclick(box,value){
var hidden=box.form.elements["txtreferral"];
if(box.checked){
var otherBoxName="txtreferral"+(3-box.name.charAt(box.name.length-1));
box.form.elements[otherBoxName].checked=false;
hidden.value=value;
}else{
hidden.value="";
}
}
</script>
</head>
<body>
<form>
<input type="checkbox" name="txtreferral1" onclick="boxclick(this,'OTHER')">
Other<br>
<input type="checkbox" name="txtreferral2" onclick="boxclick(this,'EMPS')">
Emps<br>
<input name="txtreferral" value="">
</form>
</body>
</html>

Jul 23 '05 #2

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

Similar topics

3
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"...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
4
by: PJ6 | last post by:
From a control's onkeypress the below javascript snippet is executed. I am attmpting to set the value of a hidden field... I believe I'd be able to get the contents of the hidden field by using...
1
by: Harshal P | last post by:
Hello, I am settings hidden field value from the DayRender event hadler of the asp.net calendar control, when i try to read the value of hidden field from javascript, the value is empty string. If...
1
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"...
8
by: Efi Merdler | last post by:
Hi, In my code I'm doing some xml transformation, at the end I receive a fully transformed html file. I'm setting the Value property of an hidden field control to have the content of this html...
2
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...
5
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...
14
Frinavale
by: Frinavale | last post by:
I've been trying to test my web application using Internet Explorer 8 (release candidate 1) and have been experiencing some major problems. I'm hoping you can help me with this one. I have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
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...

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.