/    Sign up×
Community /Pin to ProfileBookmark

Connect 2 Select boxes

I am trying to connect 2 select boxes together.

What I have in mind is this: The user chooses a userid from the first select box. Once they select the userid it projects data based off only the userid.

There is a second select box that holds year values so that once a year is selected it will filter the data of that userid to only show for that specific year.

I’m not that well with Javascript so I don’t know what exactly I’m trying to do in the Javascript area.

[code=html]<script type=”text/javascript”>
function saveUser(userid)
{

var userid;
showUser(userid);

}

function saveYear(year)
{
var year;
showUser(year);
}

function showUser(userid,year)
{
if (userid ==”” && year ==””)
{
document.getElementById(“txtHint”).innerHTML=””;
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,”Status_23Gs.php?q=”+userid+”&year=”+year,true);
xmlhttp.send();
}
</script>[/code]

*******Select Box1*******

[code=php]

<?php

$query=”SELECT uuid,auth,emp FROM auto_atp.Admin”;
$result=mysql_query($query);

$options=””;
while($row = mysql_fetch_array($result)){

$id=$row[‘uuid’];
$users=$row[‘uuid’];
$options.=”<OPTION VALUE=”$id”>”.$users;
}
?>

<b>UUID:</b><select id=”theuser” name=”users” onchange=”saveUser(this.value)”>
<OPTION VALUE=0><b>UID</b>
<?=$options?>
</SELECT>

[/code]
[code=php]
*****Select Box 2*******
<?php
$query=”SELECT serial,year FROM auto_atp.GeoProbe GROUP BY year ORDER BY year”;
$result=mysql_query($query);

$options=””;
while($row = mysql_fetch_array($result)){

$RES=$row[‘year’];

$options.=”<OPTION VALUE=”$RES”>”.$RES;

}
?>

<select id=”theyear” name=”year” onchange=”saveYear(this.value)”>
<OPTION VALUE=0>

<?=$options?>
</SELECT>

[/code]

****OUTPUT********
<div id=”txtHint”><b></b></div>

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @porsche21 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.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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