Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #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
Reply


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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:09 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03272 seconds
  • Memory Usage 2,166KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)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
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete