Welcome to WebmasterWorld Guest from 54.234.129.215

Forum Moderators: open

Message Too Old, No Replies

Checkbox Help

     

andrewsmd

7:11 pm on Jul 24, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Ok here is the deal I have a form with a bunch of checkboxes. When they are clicked I call a JavaScript Function that calls a php file which in turn echos its output in JavaScript (confusing I know but it is irrelevant). Here is my JavaScript function
function loadFile(targetFile) {
var day = new Date();
var id = day.getTime();
targetFile += '?'+id;
var elem = document.createElement("script");
elem.setAttribute("src", targetFile);
document.getElementsByTagName("body")[0].appendChild(elem);
}
Now this is what one of my checkboxes looks like.

<input type="checkbox" name="highmark" onclick="loadFile('highmark.php')" >

Right now whenever the user checks or unchecks the box, the "highmark.php" file runs. However I want to run the "highmark.php" file only when the user checks the box. If the user unchecks the box I don't want to do anything.

I know the logic I need, where I call this function multiple times I need to pass in the script name and the checkbox name e.g. function loadFile(targetFile, checkBoxName). Then if the checkBox has been checked I want to run my code. Otherwise I don't want to do anything. I am not a JavaScript programmer so I don't know the syntax. Any help? Thanks,

Trace

7:29 pm on Jul 24, 2008 (gmt 0)

10+ Year Member



Simply check to see if the checkbox is checked;

<input type="checkbox" name="highmark" onclick="if(this.checked){loadFile('highmark.php')}" >

Hope it helps.

andrewsmd

9:05 pm on Jul 24, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



That does work, but now when I refresh my page I loose the checkbox being checked. I want to be able to refresh the page and not loose the checkbox being checked. Is there any way around that? Thanks,

Arno_Adams

8:55 am on Jul 25, 2008 (gmt 0)

10+ Year Member



Store the selected items in a database/session/cookie.

HTH, Tom

andrewsmd

12:29 pm on Jul 25, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Are you talking about a session with PHP or JavaScript. If I do a PHP session then I would have to print that session variable for every checkbox and you have no idea how many checkboxes I have. If you are talking about some other kind of session variable I'm all ears.

Arno_Adams

3:45 pm on Jul 26, 2008 (gmt 0)

10+ Year Member



Javascript doesn't support sessions. I meant PHP sessions. How many checkboxes are there? I don't see the problem.

Tom

andrewsmd

2:16 pm on Jul 28, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Over 200 checkboxes the problem is unless I restructure my entire web page, I would have to output a php variable for each checkbox e.g. <input type = "checkbox" name = "checkbox1" value = "<?php echo($_SESSION['checkbox1Value']); ?>"> <input type = "checkbox" name = "checkbox2" value = "<?php echo($_SESSION['checkbox1Value2']); ?>"> and that would be ugly and inconvenient.

Arno_Adams

9:30 am on Jul 29, 2008 (gmt 0)

10+ Year Member



Stuff all the checkboxes in one array and put that in one session. Does that help?

Tom

andrewsmd

11:47 am on Jul 29, 2008 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



No because I have html in front of each array with different text and each of the check boxes have to have a different name. Even if I did output them like that, I would still have to pass in all of the checkbox names and the html with different text in each one. Since I'm already done with the page pretty much, I'm just going to leave it

Arno_Adams

11:55 am on Jul 29, 2008 (gmt 0)

10+ Year Member



That's your call, I just mentioned another option.

Tom

 

Featured Threads

Hot Threads This Week

Hot Threads This Month