/    Sign up×
Community /Pin to ProfileBookmark

checkbox array vars across pages

Hi folks:

I have a page of results taken from a DB query and each result has a checkbox next to it with a unique value taken from the DB.

If there are more than 50 results I have previous->next links in place.

I would love to be able to save the users checkbox selections, like save the unique checkbox values to a JS array across multiple pages whenever “next” is selected – but I have no idea how one might go about this. ?

Can anyone help or point me to an online resource that can? If you use Yahoo mail and you’ve ever selected multiple addresses from your address book across multiple pages – then this is a perfect example of what I need.

Thanks in advance for any pointers ?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@JonaNov 09.2004 — [font=trebuchet ms]Set a cookie. If you're using a server-side language, you shouldn't have a lot of trouble doing this. There's no need for JavaScript, is there?[/font]
Copy linkTweet thisAlerts:
@phptekauthorNov 10.2004 — Cheers for your quick reply - and for sure, I was thinking along the lines of a cookie, using PHP's session functionality - one of those just-before-sleep moments of clarity ?

I thought about JS as that's how the only other system I've seen that does what I want, does it - ie: Yahoo! Mail.

Thanks a lot regardless ?
Copy linkTweet thisAlerts:
@KorNov 10.2004 — Well, if you insist, here's a javascript solution based on sending some variables through the address bar as queries;

in index.html
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
function sendV(){
c=document.getElementsByTagName('input');
nv=new Array()
j=0;
for(var i=0;i<c.length;i++){
if((c[i].type=='checkbox')&&(c[i].checked)){
nv[j]=[c[i].name,c[i].value];
j++;
}
}
sended=''
for(var i=0;i<nv.length;i++){
sended = sended+'_'+nv[i][0]+'='+nv[i][1];
}
location.href='next.html'+'?'+sended;
}
</script>
</head>
<body>
<form>
<input name="one" type="checkbox" value="1">ONE<br>
<input name="two" type="checkbox" value="2">TWO<br>
<input name="three" type="checkbox" value="3">THREE<br>
<input name="but" type="button" value="Next" onclick="sendV()">
</form>
</body>
</html>
[/code]


and in next.html
[code=php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script language="JavaScript" type="text/JavaScript">
function writeD(){
var a = location.href.split('?')
var a = a[a.length-1].split('_');
var texts='';
var cName = new Array()//the checked names as an array
var cValue = new Array()//the checked values as an array
var j=0;
for(var i=1;i<a.length;i++){
cName[j]=a[i].split('=')[0];
cValue[j]=a[i].split('=')[1];
texts=texts+'name= '+cName[j]+' ; '+'value= '+cValue[j]+'<br>';
j++
}
document.getElementById('txt').innerHTML=texts;
}
onload=writeD;
</script>
</head>
<body>
NEXT PAGE<br>
On the index page you have checked the boxes:<br>
<div id="txt"></div>
</body>
</html>
[/code]
×

Success!

Help @phptek spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...