[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.4

selected item from combo / drop down to populate text boxes on the same page

Asked by sdeby in PHP and Databases

Tags: datacombo, item, selected

Hi experts,

I have a table of postcodes and I am wanting to get the user to select the city, state postcode from a combo box (displayed like city, state, postcode) and have it populate the next two text fields of "State" and "Postcode". I am looking for something like an onchange function to fill the boxes.

The postcode data comes from tblPostcode

Thanks for your help.

the code is ...

enquiry_dml.php

<?php

function insert()
{
      global $HTTP_SERVER_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_POST_FILES, $Translation;
      
      if(get_magic_quotes_gpc())
      {
            $enqDateStamp = $HTTP_POST_VARS["enqDateStamp"];
            $enqUsername = $HTTP_POST_VARS["enqUsername"];
            $city = $HTTP_POST_VARS["city"];
            $state = $HTTP_POST_VARS["state"];
            $postcode = $HTTP_POST_VARS["postcode"];
      }
      else
      {
            $enqDateStamp = addslashes($HTTP_POST_VARS["enqDateStamp"]);
            $enqUsername = addslashes($HTTP_POST_VARS["enqUsername"]);
            $city = addslashes($HTTP_POST_VARS["city"]);
            $state = addslashes($HTTP_POST_VARS["state"]);
            $postcode = addslashes($HTTP_POST_VARS["postcode"]);
      }
      
      sql("insert into tblEnquiries (city, state, postcode) values ("  . (($city != "") ? "'$city'" : "NULL") . ", " . (($state != "") ? "'$state'" : "NULL") . ", " . (($postcode != "") ? "'$postcode'" : "NULL") . ")");
      return mysql_insert_id();
}


function update($selected_id)
{
      global $HTTP_SERVER_VARS, $HTTP_GET_VARS, $HTTP_POST_VARS, $Translation;
      
      if(get_magic_quotes_gpc())
      {
            $enqDateStamp = $HTTP_POST_VARS["enqDateStamp"];
            $enqUsername = $HTTP_POST_VARS["enqUsername"];
            $city = $HTTP_POST_VARS["city"];
            $state = $HTTP_POST_VARS["state"];
            $postcode = $HTTP_POST_VARS["postcode"];
      }
      else
      {
            $enqDateStamp = addslashes($HTTP_POST_VARS["enqDateStamp"]);
            $enqUsername = addslashes($HTTP_POST_VARS["enqUsername"]);
            $city = addslashes($HTTP_POST_VARS["city"]);
            $state = addslashes($HTTP_POST_VARS["state"]);
            $postcode = addslashes($HTTP_POST_VARS["postcode"]);
      }

      sql("update tblEnquiries set " . "city=" . (($city != "") ? "'$city'" : "NULL") . ", " . "state=" . (($state != "") ? "'$state'" : "NULL") . ", " . "postcode=" . (($postcode != "") ? "'$postcode'" : "NULL") . " where enquiries_id='$selected_id'");
}

function form($selected_id = "", $AllowUpdate = 1, $AllowInsert = 1, $AllowDelete = 1)
{
      // function to return an editable form for a table records
      // and fill it with data of record whose ID is $selected_id. If $selected_id
      // is empty, an empty form is shown, with only an 'Add New'
      // button displayed.
      
      global $Translation;
      
      if(!$AllowInsert && $selected_id==""){  return ""; }
      
      
      // combobox: city
      $combo_city = new DataCombo;
      $combo_city->Query = "select postcodes_id, city, state, postcode from tblPostcodes order by city";
      $combo_city->SelectName = "city";

      if($selected_id)
      {
            $res = sql("select * from tblEnquiries where enquiries_id='$selected_id'");
            $row = mysql_fetch_array($res);
            $combo_state->SelectedData = $row["state"];
            $combo_postcode->SelectedData = $row["postcode"];
      }
      $combo_city->Render();
                $combo_state->Render();
                $combo_postcode->Render();

      
      // code for template based detail view forms
      
      // open the detail view template
      $templateCode=@implode('', @file('./tblEnquiries_templateDV.html'));
      
      // process form title
      $templateCode=str_replace('<%%DETAIL_VIEW_TITLE%%>', 'Enquiries detailed view', $templateCode);
      // process buttons
      if($AllowInsert){
            $templateCode=str_replace('<%%INSERT_BUTTON%%>', "<input type=image src=insert.gif name=insert alt='" . $Translation['add new record'] . "'>", $templateCode);
      }else{
            $templateCode=str_replace('<%%INSERT_BUTTON%%>', '', $templateCode);
      }
      if($selected_id){
            if($AllowUpdate){
                  $templateCode=str_replace('<%%UPDATE_BUTTON%%>', "<input type=image src=update.gif vspace=1 name=update alt='" . $Translation["update record"] . "'>", $templateCode);
            }else{
                  $templateCode=str_replace('<%%UPDATE_BUTTON%%>', '', $templateCode);
            }
            if($AllowDelete){
                  $templateCode=str_replace('<%%DELETE_BUTTON%%>', "<input type=image src=delete.gif vspace=1 name=delete alt='" . $Translation['delete record'] . "' onClick=\"return confirm('" . $Translation['are you sure?'] . "');\">", $templateCode);
            }else{
                  $templateCode=str_replace('<%%DELETE_BUTTON%%>', '', $templateCode);
            }
            $templateCode=str_replace('<%%DESELECT_BUTTON%%>', "<input type=image src=deselect.gif vspace=1 name=deselect alt='" . $Translation['deselect record'] . "'>", $templateCode);
      }else{
            $templateCode=str_replace('<%%UPDATE_BUTTON%%>', '', $templateCode);
            $templateCode=str_replace('<%%DELETE_BUTTON%%>', '', $templateCode);
            $templateCode=str_replace('<%%DESELECT_BUTTON%%>', '', $templateCode);
      }
      
      // process combos
      $templateCode=str_replace('<%%COMBO(city)%%>', $combo_city->HTML, $templateCode);
      $templateCode=str_replace('<%%COMBOTEXT(city)%%>', $combo_city->MatchText, $templateCode);
      $templateCode=str_replace('<%%COMBO(state)%%>', $combo_state->HTML, $templateCode);
      $templateCode=str_replace('<%%COMBOTEXT(state)%%>', $combo_state->MatchText, $templateCode);
      $templateCode=str_replace('<%%COMBO(postcode)%%>', $combo_postcode->HTML, $templateCode);
      $templateCode=str_replace('<%%COMBOTEXT(postcode)%%>', $combo_postcode->MatchText, $templateCode);
      
      // process images
      $templateCode=str_replace('<%%UPLOADFILE(enquiries_id)%%>', '', $templateCode);
      $templateCode=str_replace('<%%UPLOADFILE(enqDateStamp)%%>', '', $templateCode);
      $templateCode=str_replace('<%%UPLOADFILE(enqUsername)%%>', '', $templateCode);
      $templateCode=str_replace('<%%UPLOADFILE(city)%%>', '', $templateCode);
      $templateCode=str_replace('<%%UPLOADFILE(state)%%>', '', $templateCode);
      $templateCode=str_replace('<%%UPLOADFILE(postcode)%%>', '', $templateCode);
      
      // process values
      if($selected_id){
            $templateCode=str_replace('<%%VALUE(enquiries_id)%%>', htmlspecialchars($row['enquiries_id'], ENT_QUOTES), $templateCode);
            $templateCode=str_replace('<%%VALUE(enqDateStamp)%%>', htmlspecialchars($row['enqDateStamp'], ENT_QUOTES), $templateCode);
            $templateCode=str_replace('<%%VALUE(city)%%>', htmlspecialchars($row['city'], ENT_QUOTES), $templateCode);
            $templateCode=str_replace('<%%VALUE(state)%%>', htmlspecialchars($row['state'], ENT_QUOTES), $templateCode);
            $templateCode=str_replace('<%%VALUE(postcode)%%>', htmlspecialchars($row['postcode'], ENT_QUOTES), $templateCode);
      }else{
            $templateCode=str_replace('<%%VALUE(enquiries_id)%%>', '', $templateCode);
            $templateCode=str_replace('<%%VALUE(enqDateStamp)%%>', '', $templateCode);
            $templateCode=str_replace('<%%VALUE(city)%%>', '', $templateCode);
            $templateCode=str_replace('<%%VALUE(state)%%>', '', $templateCode);
            $templateCode=str_replace('<%%VALUE(postcode)%%>', '', $templateCode);
      }
      
      // process translations
      foreach($Translation as $symbol=>$trans){
            $templateCode=str_replace("<%%TRANSLATION($symbol)%%>", $trans, $templateCode);
      }
      
      // finally, clear scrap
      $templateCode=str_replace('<%%', '<!--', $templateCode);
      $templateCode=str_replace('%%>', '-->', $templateCode);

      return $templateCode;
}
?>

enquiry_form.html

<br>
<table border=1 bordercolor=navy cellpadding=0 cellspacing=0>
      <tr>
            <td>
                  <div class=TableTitle><%%DETAIL_VIEW_TITLE%%></div>
                  </td>
            </tr>
      <tr>
            <td>
                  <table>
                        <tr>
                              <td colspan=2></td>
                              <td rowspan=6 valign=top>
                                    <div><%%UPDATE_BUTTON%%></div>
                                    <div><%%DELETE_BUTTON%%></div>
                                    <div><%%DESELECT_BUTTON%%></div>
                                    <br>
                                    <div><%%INSERT_BUTTON%%></div>
                                    </td>
                              </tr>
                                                <tr>
                              <td class=TableHeader valign=top>
                                    <div class=TableHeader style="text-align:right;">City / suburb</div>
                                    </td>
                              <td class=TableBody width=300><%%COMBO(city)%%>&nbsp;&nbsp;</td>
                              </tr>
                        <tr>
                              <td class=TableHeader valign=top>
                                    <div class=TableHeader style="text-align:right;">State / territory</div>
                                    </td>
                              <td class=TableBody width=300><input size=50 type=text class=TextBox name=city value="<%%VALUE(state)%%>">&nbsp;&nbsp;</td>
                              </tr>
                        <tr>
                              <td class=TableHeader valign=top>
                                    <div class=TableHeader style="text-align:right;">Postcode</div>
                                    </td>
                              <td class=TableBody width=300><input size=50 type=text class=TextBox name=postcode value="<%%VALUE(postcode)%%>">&nbsp;&nbsp;</td>
                              </tr>
                                                </table>
                  </td>
            </tr>
      </table>
 
Related Solutions
Keywords: selected item from combo / drop dow…
 
Loading Advertisement...
 
[+][-]11/04/06 03:10 AM, ID: 17872765Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/06 03:16 PM, ID: 17877963Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/06/06 07:55 AM, ID: 17881733Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/07/06 10:42 AM, ID: 17891840Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/07/06 12:03 PM, ID: 17892419Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/07/06 08:43 PM, ID: 17895574Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/08/06 07:04 AM, ID: 17898547Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: PHP and Databases
Tags: datacombo, item, selected
Sign Up Now!
Solution Provided By: lucki_luke
Participating Experts: 1
Solution Grade: A
 
[+][-]11/09/06 01:35 PM, ID: 17909735Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/09/06 02:29 PM, ID: 17910150Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/06 04:18 AM, ID: 17913601Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/10/06 04:47 AM, ID: 17913725Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/06 04:09 PM, ID: 17918944Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/10/06 09:30 PM, ID: 17919979Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/10/06 10:33 PM, ID: 17920107Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-89