I need a requirement here, i want to use JavaScript so that i don't want users to check both the check boxes. They should check only one and in case if they check both, an alert message should pop up
Thanks
Jack
3 1531
hi
I wrote a sample code for you.
[HTML]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<script language="javas cript">
<!--
function check()
{
var check1 = document.getEle mentById("check 1");
var check2 = document.getEle mentById("check 2");
if (check1.checked && check2.checked )
alert ("You should check only 1.");
}
-->
</script>
<input type="checkbox" id="check1" />Check1
<br />
<input type="checkbox" id="check2" />Check2
<br />
<input type="button" value="test" onclick="check( );"/>
</body>
</html>
[/HTML]
and another suggestion for you:
you can use radio box to satisfy your requirement without javascript.here is another sample code for you.
[HTML]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<input type="radio" id="check1" name="check" />Check1
<br />
<input type="radio" id="check2" name="check" />Check2
</body>
</html>
[/HTML]
attention: you should give these 2 radio box a same name,and then,they can work together.
hope it helps.
Thanks a lot for your reply
My requirement is, i have check boxes in my PDF file and i dont want the user to check both the boxes. The idea of Radio button would definitely work, but i do not have the access to change that.
I am trying to run the JavaScript in the PDF file. The way to add the script in the PDF file is
1) Right Click on the check box and then Properties and then click on the Actions Tab and then "Select Action"--> "Run a JavaScript"
Unfortunately your script is not working, it might be for an HTML page. Do you have any other ideas
Thanks
Jack
hi
i'm sorry i have no idea about the javascript in PDF,but I guess it makes no difference.
my code : -
var check1 = document.getElementById("check1");
-
var check2 = document.getElementById("check2");
-
can work,i guess.But you couldn't copy it directly.you should change the parameter in getElementById. The parameter is the id of the check box in your PDF file. if you can find the id,you will get the right script.
hope it helps.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Adrian Parker |
last post by:
I have a PHP generated page which displays X many records. Each record has
a checkbox preceding it. The user checks several checkboxes, and hits a
delete button. All the corresponding records will be deleted.
But I'm running into difficulty...
Right now the NAME property of each check box is the primary key of the
corresponding record. Hence if I know which checkboxes are checked, I
simply use DELETE using the NAME value.
|
by: NotGiven |
last post by:
I have a form with several questions. Within each question there are
several checkboxes. I need to ensure that the user checks at least one
checkbox. They can check more but must check at least one.
How would I do this in Javascript?
Many thanks.
|
by: terence.parker |
last post by:
I currently have the following JS in my header:
function checkall(thestate) {
var checkboxes=eval("document.forms.EssayList.file_id")
for (i=0;i<checkboxes.length;i++)
checkboxes.checked=thestate
}
This works fine - but the problem is that it doesn't work with my
|
by: Travis.Box |
last post by:
I have an MS Access userform with 16 Check Boxes. Each of the
checkboxes has a different option value, which coincides with the Check
Box name (eg. cb01.OptionValue = 1). At the bottom of the form is a
command button. When the command button is clicked, I need the VBA
scripting to determine which Check Box has been selected, and then
assign a vaule to a string based on which Check Box has been selected.
What I'm having trouble figuring...
|
by: Jaime Stuardo |
last post by:
Hi all..
I have a DataGrid with checkboxes. In the header I have a "check all"
checkbox.
I'm wondering if there is an easy way to check all checkboxes using that
checkbox. I could do it using JavaScript code, but the main problem I have
is that checkboxes ids aren't kept when the datagrid is rendered, for
example, if the checkboxes have the name chkNumid, when the datagrid is
rendered, the checkboxes become dgDataGrid_ctl02_chkNumId,
| |
by: babu17 |
last post by:
hi,
i have a list of checkboxes, the number of checkboxes is dynamic. All
the checkboxes have same name.
i am trying to get the length of selected checkboxes.
<input type=checkbox name=name1 value=1>
<input type=checkbox name=name1 value=2>
........ get dynamically.
when i try to get the length in javascript like
|
by: rn5a |
last post by:
All the rows in a DataGrid, including the Header, are accompanied with
a CheckBox. I want that when the CheckBox in the Header is checked,
then all the CheckBoxes should automatically get checked. I set the
AutoPostBack property of the CheckBox in the Header to True & am
invoking a sub named 'CheckAllRows' on the CheckedChanged event of this
CheckBox. The CheckBox in the Header exists within the HeaderTemplate
of a TemplateColumn in the...
|
by: dkultasev |
last post by:
Hello,
I have small script which generates some listboxes. Their names are
listXX (list01, list02, list03....). How to check if there are checked
or not ? If I have 1 listbox and have it's name I do $_POST.
But what to do in that situation ?
Sincerely,
Dmitrij
|
by: Frinavale |
last post by:
I'm working on an ASP.NET application using VB.NET for server side code.
I have a GridView listing a bunch of stuff. Above the GridView I have a checkbox named "ChkBx_SelectAll". If this checkbox is checked, all of the rows in the GridView are checked, if this checkbox is unchecked, all of the rows in the GridView are unchecked.
This checking/unchecking of the checkboxes in the GridView is handled by a JavaScript method:
function...
|
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: 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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: 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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |