View Single Post
  #1  
Old 11-05-2007, 04:24 AM
Iskib Iskib is offline
 
Join Date: May 2006
Posts: 55
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Forms - ajax, php/mysql

Maybe someone can help.

I am making a form to submit events. I want to let the user select a country and from the country a dropdown "select" opens with the eithier state (US) Prov (CA) or Region.

The countries are pulled form the database as are the states, provs, regions I want it to do this without reloading the page.

here is what I have so far top of the page I have:

Code:
<?php

$country = $state = null; 

if(isset($_GET["country"]) && is_numeric($_GET["country"]))
{
    $country = $_GET["country"];
}

if(isset($_GET["state"]) && is_numeric($_GET["state"]))
{
    $state = $_GET["state"];
}

?>

<script language="JavaScript">

function autoSubmit()
{
    var formObject = document.forms['events'];
    formObject.submit();
}

</script>
Then have all the normal form fields (these are not the problem)
name of event
description of event
date/time of the event
City of the event (this is typed)

Then I have this for country and state/prov/region

Code:
<td><?php echo $lang['event_country'];?></td>
              <td><select onChange="autoSubmit();" id="country" name="country" class="form_select" style="width:70%;">
			    <option value="null"></option>
			    <?php $fetch_countries = sql_query("SELECT * FROM countries"); 
			     while ($countries = mysql_fetch_array($fetch_countries)) { 
			
	                echo ("<option value=\"$countries[country_id]\" " . ($country == $countries[country_id] ? "selected" : "") . ">$countries['country_name']</option>");
	            
			   }
        
        ?>
              </select></td>
            </tr>
            <tr>
            <td><?php echo $lang['event_stateprov'];?></td>
            <?php
    
    if($country != null && is_numeric($country))
    {
    
    ?>
              
        <option value="null"></option>
              <td><select name="stateprov" class="form_select" style="width:70%" onChange="autoSubmit();">
              <option value="null"></option>
              <?php
        
      	$fetch_stateprov = sql_query("SELECT state_id, state_name FROM states WHERE country_id = $country";		  
      
          $statesprov = sql_query($fetch_stateprov);
        while($stateprov = mysql_fetch_array($statesprov))  
       
        {   
 echo ("<option value=\"$stateprov[state_id]\" " . ($state  == $stateprov["state_id"] ? "selected" : "") . ">$stateprov[state_name]</option>");  
                }
        
        ?>
        
    </select>
    
    <?php  } ?>
Again I am learning php etc...

Do you see anything wrong with the code and what can I add to not reload the page and populate the second drop down

Thanks in advance!

--------------- Added [DATE]1194314774[/DATE] at [TIME]1194314774[/TIME] ---------------

I know i need to change the function , but I have no idea what to
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01343 seconds
  • Memory Usage 1,774KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete