JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 7th, 2013, 10:41 AM
jennypretty jennypretty is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2008
Posts: 17 jennypretty User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 19 sec
Reputation Power: 0
PHP option selection help

Hello,

I tried to create a drop-down for users to pick. If a user pick 'United States', then Us States will show up. Otherwise, 'Outside usa' will show.

It didn't work. Here is my code:

dt>Country</dt>
<dd>
<select class="select" id="field_country" name="country">
<option value="1" selected="selected">United States</option>
<option value="2">Canada</option><option value="3">Afghanistan</option>
</select>
</dd>
<?php if (field_country) == "1") { ?>
<dt>State</dt>
<dd>
<select class="select" id="field_state" name="state">
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">Arizona</option>
<option value="5" selected="selected">California</option>
</select>
</dd>
<?php } else { ?>
<dt>State</dt>
<dd>
<select class="select" id="field_state" name="state">
<option value="6" selected="selected">Outside Usa</option>
</select>
</dd>
<?php } ?>

Thanks.

Reply With Quote
  #2  
Old January 7th, 2013, 11:22 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,907 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Month 16 h 33 m 11 sec
Reputation Power: 581
Please enclose your code in [ PHP ] tags. See the sticky at the top of this forum.

I think you are confusing what happens where. PHP is server side. Once the page is served out that ends PHP's involvement and it knows nothing after that. Drop down selections are made on the browser (client) side so PHP will never see it. You need to accomplish what you want with JavaScript.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old January 7th, 2013, 01:12 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 658 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 7 h 58 m 5 sec
Reputation Power: 69
Actually you can use client side or server side language to do this or you can use both (like my example below).

Code:
<?php
$field_country = $_GET["country"];
?>

<script>
function redirectCountry(setCountry)
{
 setCountry = parseInt(setCountry);
  if (setCountry > 0) {
   document.location.href = "?country=" + setCountry;
  }
}
</script>

<dt>Country</dt>
<dd>
<select class="select" id="field_country" name="country" onchange="redirectCountry(this.value)">
<option value="0"/>Select Your Country</option>
<option value="1">United States</option>
<option value="2">Canada</option><option value="3">Afghanistan</option>
</select>
</dd>
<?php 
if ($field_country == 1) {
echo '<dt>State</dt>
<dd>
<select class="select" id="field_state" name="state">
<option value="1">Alabama</option>
<option value="2">Alaska</option>
<option value="3">Arizona</option>
<option value="5" selected="selected">California</option>
</select>
</dd>';
} 
else if ($field_country > 1) {
echo '<dt>State</dt>
<dd>
<select class="select" id="field_state" name="state">
<option value="6" selected="selected">Outside Usa</option>
</select>
</dd>';
}
?>


It all depends on how you want to display your select menu(s).

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Using one form field to toggle others [was "PHP option selection help" in PHP]

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap