/    Sign up×
Community /Pin to ProfileBookmark

How to control state list box if there is selected country USA?

question:I have seen in web sites that on registration page there is no state but if there is selected country USA it will refresh page and show field with list boy states. Do you know how to do it with function? Need help ?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachOct 30.2006 — Thats done via Javascript

you need to use the onChange attribute in the select tag. something like this

[code=html]

<select id="country" name="country" onChange="location.href='http://www.mydomain.com/register.php&country='+this.options[this.selectedIndex].value;">

<option value="1">USA</option>
<option value="2">UK</option>

</select>
[/code]



then in the register form you need to do something like this

[code=php]

if($_GET['country']==1) {

// state drop down goes here


}

[/code]
Copy linkTweet thisAlerts:
@bathulasumanNov 01.2006 — hi friend try this php code

"file name="123.php"

Religion

<select size="1" name="religion" onChange="submitform()">

<OPTION value="0">Select</OPTION>

<OPTION value="Hindu" <?if ($religion=="Hindu") echo "selected"?>>Hindu</OPTION>

<OPTION value="Muslim" <?if ($religion=="Muslim") echo "selected"?>>Muslim</OPTION>

<OPTION value="Christian" <?if ($religion=="Christian") echo "selected"?>>Christian</OPTION>

<OPTION value="Jain" <?if ($religion=="Jain") echo "selected";?>>Jain</OPTION>

<OPTION value="Sikh" <?if ($religion=="Sikh") echo "selected";?>>Sikh</OPTION>

<OPTION value="Buddhist" <?if ($religion=="Buddhist") echo "selected";?>>Buddhist</OPTION>

<OPTION value="Parsi" <?if ($religion=="Parsi") echo "selected";?>>Parsi</OPTION>

<OPTION value="Jewish" <?if ($religion=="Jewish") echo "selected";?>>Jewish</OPTION>

<OPTION value="Religion No Bar" <?if ($religion=="Religion No Bar") echo "selected";?>>Religion

No Bar</OPTION>

</select>

Caste

<?

$castesql= "select * from caste where religion='$religion' order by caste";
$casters = mysql_query($castesql);
$num = mysql_num_rows($casters);
if ($num > 0):
?>
<select size="1" name="caste">
<option value="0">select</option>
<?php while($castearr = mysql_fetch_array($casters)){extract($castearr);?>
<option value="<?=$caste?>" <? if($caste1==$caste) echo "selected";?>>
<?=$caste?>
</option>
<?php } ?>
</select>
<?php else: ?>
<font color="red" face=verdana size=1>No caste found.</font>
<?php endif; ?>


function submitform()

{

document.step2frm.action="123.php";

document.step2frm.submit();

}
×

Success!

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