vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Forms - ajax, php/mysql (https://vborg.vbsupport.ru/showthread.php?t=161955)

Iskib 11-05-2007 04:24 AM

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


All times are GMT. The time now is 01:10 AM.

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.01039 seconds
  • Memory Usage 1,719KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (1)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete