473,327 Members | 1,896 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,327 software developers and data experts.

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 handleHighCatSelect(obj)
{
var highCatName = obj.name;
var highCatNameInMidCat = highCatName.substring(0,5) + "00" +
highCatName.substring(5,6);
alert(highCatName);
var length = document.frm.elements.length;
for (var i=0;i<length;i++)
{
var formObj = document.basicSearchMFSFrm.elements[i];
var currName = formObj.name;
var currValue = formObj.value;

if ((formObj.type == 'radio' || formObj.type == 'checkbox')
&& (currName.indexOf('0001-') != -1) )
{
if ((currName.indexOf(highCatNameInMidCat) != -1) ||
(currName == highCatName ) )
{
formObj.checked = true;
}
else
{
formObj.checked = false;
}
}
}
frm.submit();
}

Jul 23 '05 #1
2 2191
"Glenn" <gl*********@yahoo.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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*****@agricoreunited.com>
comp.lang.javascript 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
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...
5
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...
4
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...
2
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...
2
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...
10
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...
9
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...
1
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...
10
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
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.