473,749 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Submit adding back in checkboxes that were unchecked in javascript

The following script is supposed to have high categories as radio
buttons and mid categories as check boxes. Clicking the radio button
is supposed to select all checkboxes under it and submit the form.

RADIO (ID = 0001-1 VALUE="")
CHECK (ID=0001-0011)
CHECK (ID=0001-0012)
RADIO (ID = 0001-2 VALUE="")
CHECK (ID=0001-0021)
CHECK (ID=0001-0022)

The code appears to be checking and unchecking the correct checkboxes.
But when the submit occurs, the buttons that were unchecked become
checked again.
function handleHighCatSe lect(obj)
{
var highCatName = obj.name;
var highCatNameInMi dCat = highCatName.sub string(0,5) + "00" +
highCatName.sub string(5,6);
alert(highCatNa me);
var length = document.frm.el ements.length;
for (var i=0;i<length;i+ +)
{
var formObj = document.basicS earchMFSFrm.ele ments[i];
var currName = formObj.name;
var currValue = formObj.value;

if ((formObj.type == 'radio' || formObj.type == 'checkbox')
&& (currName.index Of('0001-') != -1) )
{
if ((currName.inde xOf(highCatName InMidCat) != -1) ||
(currName == highCatName ) )
{
formObj.checked = true;
}
else
{
formObj.checked = false;
}
}
}
frm.submit();
}

Jul 23 '05 #1
2 2215
"Glenn" <gl*********@ya hoo.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
The code appears to be checking and unchecking the correct checkboxes.
But when the submit occurs, the buttons that were unchecked become
checked again.


I'm guessing you have neglected to provide a <FORM ACTION="...">, so the
page is submitting to itself. When it does this, the page reloads in
it's default state.

If you want to preserve the state of the <FORM>, you need to either:

1) store the state in cookies on the client before the form submits,
then when the page reloads, read that cookie and restore the state using
client-side JavaScript.

2) remember the state on the server using some server-side technology
(PHP, JSP, ASP, etc) and when you serve up the page after the GET/POST,
restore the state from the server.

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #2
What I finally found was that my javascript was working as expected.
The problem was that the page had hidden fields to keep track of
selections on other pages. This page accidentally had the wrong hidden
fields on the page and the old selections were being resubmitted.
Thanks for your help.

Jul 23 '05 #3

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

Similar topics

3
2031
by: lkrubner | last post by:
A friend using my software called me and said some templates were being reset to default when he submitted a form. I'm trying to track down the problem. It looks like when he assigns a template to some webpages, any page not assigned to that template is having its template reset to the default. I'm not sure why. I've been assuming that with checkboxes nothing gets submitted to the server if the checkbox is left unchecked. Isn't that so? ...
5
2200
by: Dave D. | last post by:
I have a total of 8 checkboxes, but the user is only allowed to check any three of them. After have been checked I have an alert box saying that only 3 boxes can be checked. I'm trying to get so that it disable's the checkboxes that are not checked, but then if one of the three get unchecked, then all checkboxes become enabled again. Here's my code so far....(In Javascript) function chkCount() { var i = 0;
4
10787
by: Claire | last post by:
Hello, I am having a problem in my struts application with the checkboxes in my form. I have an array of checkboxes, some of which may be already selected when the form loads. My problem is when the user then deselects one or more of these checkboxes and submits the form - they're being submitted as if they were still checked, when the user has infact deselected them. I've heard that this is a common problem, but I don't seem to be...
2
4370
by: Jim Duncan | last post by:
How can I make a client-side javascript form.submit() look enough like a postback that the browser back button will not show the previous state of the form and instead go to the previous page? I have two forms on the page. The first is a server form (runat=server) and contains a Repeater control. One of the columns contains a checkbox for each row. The second form has a hidden field that will contain a comma delimited string of the...
2
4669
by: somaskarthic | last post by:
Hi In my php code , i dynamically created table rows on button click event. Each row contain 3 selectboxes, 7 checkboxes . On each click of these elements i need to submit the form and save the data to database. After each submit , i need to display the previous added details (with some checkboxes checked and some others unchecked ..) and one new row for next updation. Here i need to collect all values submitted in the php page. There i...
10
3591
by: apparker | last post by:
I'm creating a new GUI for a program and it is for a medical exam. There are so many different things to ask someone during a history it wastes too much space to make checkboxes for everything so I had an idea: Can I simply create a list of conditions and when the doctor clicks them, they turn red? And clicking them again would make them default again? This would really make the exam better since the doctor could quickly glance at a...
9
2098
by: dfletcher | last post by:
Hi all, This is my first post so please bear with me. I have a youth soccer uniform order ASP application that loads and pulls from a SQL database that allows soccer teams to construct a uniform kit. Each piece of the uniform kit can come in a possible 14 different sizes. But some may only come in 12, 6, 3 sizes or whatever. So when the team uniform guy Creates the kit he checks what sizes are available for each jersey, shorts, socks,...
1
4516
Frinavale
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...
10
7430
by: k3pp0 | last post by:
Hello. Here's my example form: <form method="get" action=""> <p> <input type="radio" name="radio_example" id="radio1" value="radio1_val" /> <label for="radio1">radio button one</label> </p>
0
8996
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, 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...
0
8832
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,...
0
9254
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 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...
0
8256
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, 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...
1
6800
isladogs
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...
0
4879
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3319
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
2
2791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2217
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 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...

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.