/    Sign up×
Community /Pin to ProfileBookmark

php and javascript dropdowns

Hi
i have 2 dynamic javascript dropdown lists, meaning 2nd one gets populated by the choice from the 1st.
I need some php script, which will take that value from the drop downs, and create a table in htm(or php) document, listing the values depending on the drop down.
is this possible?
thanks

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@simpson97Dec 08.2004 — Yes
Copy linkTweet thisAlerts:
@tasneemauthorDec 08.2004 — how?
Copy linkTweet thisAlerts:
@simpson97Dec 08.2004 — Heres a rudimentary example:

<html>

<body>

<?php

$rowcnt = $_POST['rows'];

$colcnt = $_
POST['cols'];

if(isset($_POST['rows']))

{

print "<table border=1><tbody>";

for($r = 0; $r < $rowcnt; $r++)

{

print "<tr>";

for($c = 0; $c < $colcnt; $c++)

{

print "<td>$r - $c</td>";

}

print "</tr>";

}

print "</tbody></html>";

}

?>

<form action='atest.php' method='post'>

<select name='rows'>

<?php

for($i = 1; $i < 10; $i++)

print "<option value=$i>$i";

?>

</select>

<br />

<select name='cols'>

<?php

for($i = 1; $i < 10; $i++)

print "<option value=$i>$i";

?>

</select>

<br />

<input type=submit value='Make Table'>

</form>

</html>

</body>

Bob
Copy linkTweet thisAlerts:
@tasneemauthorDec 11.2004 — hi

thanks

but my drop down are dynamic for mysql db.

i get the complete table done beautifully with this code:
[code=php]<?php include('myconnaspfree.php');

//set defaults
$country = 'All';
$stateprov = 'allstateprov';

//create short variable name
if($HTTP_POST_VARS['country']) $country = $HTTP_POST_VARS['country'];
if($HTTP_POST_VARS['stateprov']) $stateprov = $HTTP_POST_VARS['stateprov'];
?>
[/code]

[CODE]<form name="retailerform" method="post">
<table>
<tr>
<td><label for="country"><strong>Select a Country...</strong></label><br />
<select name="country" class="selectbox">
<?php
if($country !== 'All') {
echo('<option value="'.$country.'">'.$country.'</option>'."n");
}
?>
<option value="All">All</option>
<?php
$strsql = "select distinct country from retailers order by country";
$rsTmp = mysql_query($strsql) or die("Query failed");
while($rowTmp = mysql_fetch_array($rsTmp)) {
echo "<option value='$rowTmp[0]'>$rowTmp[0]</option> ";
}
?>
</select>
<?php
?>
</td>
<td><label for="stateprov"><strong>Select a State/Province...</strong></label><br />
<select name="stateprov" class="selectbox">
<option value="allstateprov">All</option>
<?php

$strssql = "select distinct state from retailers where state <> ' ' order by country,state";
$rssTmp = mysql_query($strssql) or die("Query failed");
while($rowsTmp = mysql_fetch_array($rssTmp)) {
echo "<option value='$rowsTmp[0]'>$rowsTmp[0]</option> ";
}
?>
</select></td>
<td valign="middle">
<input name="go" type="submit" class="button" value="Search">
</td></tr></table>

</form> [/CODE]


and then i have the code table populating.

You can have a look at this page [URL=http://des-us.glwb.info/staciretailersnew.php]testpage[/URL]

I just need the code to change the state drop down list after choosing a country.

thanks
×

Success!

Help @tasneem 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.25,
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,
)...