Forum Moderators: coopster

Message Too Old, No Replies

Check whether a checkbox has been checked before submition?

         

NooK

9:06 am on Oct 23, 2007 (gmt 0)

10+ Year Member



I have a table where each row is clickable to show some more detailed information under it and that is done by passing some data through the address field.

For example

http://www.example.com/page.php?data=dataToBePassed

Also every row has a checkbox in it.

My problem is that if the user check the checkbox and clicks some row, the checkbox state is lost (Due to a new page loading).

Is there anyway I can save the checkbox state before the user goes to another page?

I think sessions would be the way to go but I am not sure if it is even possible to figure out the checkbox state before the user has submitted the form.

Best Regards

NooK

[edited by: dreamcatcher at 1:35 pm (utc) on Oct. 23, 2007]
[edit reason] Use example.com, thanks. [/edit]

Habtom

9:11 am on Oct 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think sessions would be the way to go but I am not sure if it is even possible to figure out the checkbox state before the user has submitted the form.

To get the values of a checkbox you will need to submit the form.

My problem is that if the user check the checkbox and clicks some row, the checkbox state is lost (Due to a new page loading).

Your problem lies here I guess. Why do you need to reload the page?

Habtom

cameraman

9:26 am on Oct 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sessions wouldn't help you here.
How about displaying the extra information in an iframe or a popup?
The only other ways I can think of would be to use an AJAX request to get & display the information or use javascript to append the form values to the url before redirecting.

IndiaMaster

10:46 am on Oct 23, 2007 (gmt 0)

10+ Year Member



I also think that AJAX will solve your problem. You can place a hidden DIV below each row and display the extra information in that hidden field.

iFrame is also a good solution. But the easiest way is to show the extra information in a popup window.

NooK

11:32 am on Oct 23, 2007 (gmt 0)

10+ Year Member



Well the user needs to see such information, and a popup would be just plain ugly not to mention the amount of data wouldn't look nice in a popup.

Basically the table rows are basic information about an order (So to speak) and the user can click the row to show more detailed information on the order

And at the same time each row header has a checkbox which would be used to place the order (Sending all checked orders once he presses the save button on the bottom of the page to submit the form).

Would Ajax allow me to send data to be stored in the server to be later retrieved once the used has clicked another row?

The reason I need to reload the page is because I send some data in the address field depending on what row the users click, and this data is used to get the extra information from the database and show it under the row.

Best Regards

NooK

[edited by: NooK at 11:49 am (utc) on Oct. 23, 2007]

PHP_Chimp

12:30 pm on Oct 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are going to go down the AJAX rout then you dont need to reload the whole page. As you can use the AJAX to reload the parts that need refreshing.
So if they change shipping address by un-clicking one of your checkboxes then you can reload the div/td(or whatever) has the shipping address in. Same for all of the other areas.
So you dont need to worry about storing information, as the form will have the latest version of the information on it.

The only downside of AJAX is what happens for those people who turn javascript off?

[edited by: PHP_Chimp at 12:32 pm (utc) on Oct. 23, 2007]

NooK

12:43 pm on Oct 23, 2007 (gmt 0)

10+ Year Member



I wanted dto try and avoid ajax. I think I'll work around it but seeing as I am already using AJAX elsewhere on the page I guess it wouldn't be much of a hassle, it's just the code looks nice with php and I wanted to keep it that way.

Thanks for the answers guys.

Best Regards

NooK

NooK

12:53 pm on Oct 23, 2007 (gmt 0)

10+ Year Member



Hmm seeing as we are on the topic, is there anyway to unload the AJAX info?

I mean currently the user can only see the detailed info on one order (row) but with the ajax loading the user will just be able to click row after row. Is there anyway to unload the current row before loading the data for the next one without reloading the site?

Best Regards

NooK

PHP_Chimp

1:08 pm on Oct 23, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If your AJAX is interacting with php then you could unset [uk3.php.net] the variables in php before it passes the text/XML back to the AJAX.

If it is just javascript then you can just overwrite the variables with your new ones.

supermanjnk

1:13 pm on Oct 23, 2007 (gmt 0)

10+ Year Member



You could use JavaScript to store the last row clicked and run another JavaScript function that "closes" it when you click on the link, then runs the function that gets the new data.