Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: Select Box Help

  1. #1
    Join Date
    Oct 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Select Box Help

    Hello,
    I'd like to make a states select box size 6 in a form that allows a user to select a state then hit a button titled 'add state' that then adds the state to another select box size 6 that starts out empty. the state they selected is then added to the empty select box and taken away from the first select box. there would also be a button to put the state back into the first select box. anyone have any ideas on how to do such a thing? i assume it uses javascript...

    s.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Does this help you?
    Edit: BYK Found an error in my code, here's the right code:
    HTML Code:
    <html>
    <head>
    <script type="text/javascript">
    function putIn(to,from){
    var x = document.getElementById(from);
    var i = document.getElementById(to);
    var opt = new Option(x.options[x.selectedIndex].text, x.options[x.selectedIndex].value);
    i.add(opt, undefined);
    x.remove(x.selectedIndex);
    }
    </script>
    </head>
    <body>
    <select id="1" size="6" style="width:114px">
    <option value="1">Cake</option>
    <option value="2">Cookies</option>
    <option value="3">Ice Cream</option>
    <option value="4">Lolly Pop</option>
    <option value="5">Chocolate</option>
    <option value="6">Gummy Bears</option>
    </select>
    <button onClick="putIn(2,1)">Take Away</button><br />
    <select id="2" size="6" style="width:114px">
    </select>
    <button onClick="putIn(1,2)">Put Back</button><br />
    </body>
    </html>
    Last edited by Nile; 05-25-2008 at 03:41 PM.
    Jeremy | jfein.net

  3. #3
    Join Date
    Oct 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    That DOES allow me to add the text from one select box to the other and remove it accordingly, so we're on the right track. However when I try to process the form field with php i get a NULL result for the values in the second select box with id=2.

    Here's the code I'm using with your javascript function added to my select boxes:

    <td><select name=\"geo_scope0[]\" style=\"width:auto\" id=\"1\" size=\"6\">$option_block1</select><button type=\"button\" onClick=\"putIn(2,1)\">Add >></button><br /><button type=\"button\" onClick=\"putIn(1,2)\"><< Remove</button><select name=\"geo_scope[]\" id=\"2\" style=\"width:auto\" size=\"6\"></td></tr>

    The contents of $option_block1 is so:

    for ($i=0; $i < 40; $i++) {
    $option_block1 .= "<option value=\"$states[$i]\">$states[$i]</option>";

    Any idea why the values aren't processing correctly in my addrecord script?

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Can I see your whole code?
    Last edited by Nile; 05-25-2008 at 10:07 PM.
    Jeremy | jfein.net

  5. #5
    Join Date
    Oct 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Absolutely:

    <?php
    session_start();
    if ((isset($_SESSION['username'])) && (isset($_SESSION['password']))) {

    // initialize variables
    $states = array('Statewide','Adams County','Asotin County','Benton County','Chelan County','Clallam County','Clark County','Columbia County','Cowlitz County','Douglas County','Ferry County','Franklin County','Garfield County','Grant County','Grays Harbor County','Island County','Jefferson County','King County','Kitsap County','Kittitas County','Klickitat County','Lewis County','Lincoln County','Mason County','Okanogan County','Pacific County','Pend Oreille County','Pierce County','San Juan County','Skagit County','Skamania County','Snohomish County','Spokane County','Stevens County','Thurston County','Wahkiakum County','Walla Walla County','Whatcom County','Whitman County','Yakima County');
    $option_block1 = "";
    $display_block = "";

    // populate states dropdown
    for ($i=0; $i < 40; $i++) {
    $option_block1 .= "<option value=\"$states[$i]\">$states[$i]</option>";
    }

    // create html form
    $display_block ="
    <form method=\"post\" action=\"addrecord.php\" id=\"record\" name=\"record\" onsubmit=\"return checkform();\">
    <fieldset>
    <legend>PROVIDER INFORMATION</legend>
    <table class=\"formtable\">
    <tr>
    <td class=\"label\">Provider Name:</td><td><input type=\"text\" id=\"provider_name\" name=\"provider_name\" size=\"50\" /> <font color=\"red\"<strong>REQUIRED FIELD</strong></font></td></tr>
    <tr>
    <td class=\"label\">Contact First Name:</td><td><input type=\"text\" id=\"contact_fname\" name=\"contact_fname\" size=\"30\" /></td></tr>
    <tr>
    <td class=\"label\">Contact Last Name:</td><td><input type=\"text\" id=\"contact_lname\" name=\"contact_lname\" size=\"30\" /></td></tr>
    <tr>
    <td class=\"label\">Phone:</td><td><input type=\"text\" id=\"phone\" name=\"phone\" size=\"10\" /></td></tr>
    <tr>
    <td class=\"label\">E-mail:</td><td><input type=\"text\" id=\"email\" name=\"email\" size=\"30\" /></td></tr>
    <tr>
    <td class=\"label\">URL:</td><td><input type=\"text\" id=\"url\" name=\"url\" size=\"50\" /></td></tr>
    <tr>
    <td class=\"label\">Eligibility Requirements:</td><td><textarea name=\"eligibility_req\" cols=\"90\" rows=\"12\"></textarea></td></tr>
    <tr>
    <td class=\"label\">Program Description:</td><td><textarea name=\"program_desc\" cols=\"90\" rows=\"12\"></textarea></td></tr>
    <tr>
    <td class=\"label\">Deadline:</td><td><select name=\"deadline\" id=\"deadline\"><option value=\"yes\">yes</option><option value=\"no\">no</option></select></td></tr>

    <tr>
    <td class=\"label\">Application Procedures:</td><td><input type=\"text\" id=\"app_proc\" name=\"app_proc\" size=\"50\" value=\"See Website\" /></td></tr>
    <tr>
    <td class=\"label\">Geographic Scope:<br />
    (may select multiple)
    </td>
    <td><select name=\"geo_scope0[]\" style=\"width:auto\" id=\"1\" size=\"6\">$option_block1</select><button type=\"button\" onClick=\"putIn(2,1)\">Add >></button><br /><button type=\"button\" onClick=\"putIn(1,2)\"><< Remove</button><select name=\"geo_scope[]\" id=\"2\" style=\"width:auto\" size=\"6\"></td></tr>
    </table>
    </fieldset>
    <div align=\"center\">
    <input type=\"submit\" name=\"submit\" value=\"Add this Record\" class=\"submit\" id=\"submit\" /></div>
    </form>";

    ?>

    <html>
    <head>
    <title>Enter a New Record</title>
    <link rel="stylesheet" href="style/infra-db.css" type="text/css">
    <script src="scripts/checkform.js" type="text/javascript"></script>
    <script type="text/javascript">
    function putIn(to,from){
    var x = document.getElementById(from);
    var i = document.getElementById(to);
    var opt = new Option(x.options[x.selectedIndex].text, x.options[x.selectedIndex].value);
    i.add(opt, undefined);
    x.remove(x.selectedIndex);
    }
    </script>
    </head>
    <body>

    <div class="header">
    <p class="title">Washington Infrastructure Database</p>
    <p class="subtitle">Add New Record</p>
    <p class="links"><strong>Add Record</strong> | Modify Record | <a href="pick_viewrecord.php">View Records</a></p>
    </div>

    <?php

    echo "$display_block";

    } else { header("Location: http://" . $_SERVER['HTTP_HOST'] .
    dirname($_SERVER['PHP_SELF']) . "/login.php");
    exit(); }?>

    </body>
    </html>

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Can I see addrecord.php, it will help me. Because you said that you were having problems with when it sends the data.
    Jeremy | jfein.net

  7. #7
    Join Date
    Oct 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes, it's here. You'll notice there are a lot more fields i'm processing from the previous form (i edited those out of my last post to be less confusing for you).

    <?php
    session_start();
    if ((isset($_SESSION['username'])) && (isset($_SESSION['password']))) {

    //includes
    include("connection.php");
    include("escape.php");

    // set variables

    $geo_scope = $_POST['geo_scope'];

    if (isset($geo_scope) && ($geo_scope != "")) {
    foreach ($geo_scope as $v) {
    switch ($v) {
    case 'Statewide':
    $statewide = 'statewide';
    break;
    case 'Adams County':
    $adams = 'adams';
    break;
    case 'Asotin County':
    $asotin = 'asotin';
    break;
    case 'Benton County':
    $benton = 'benton';
    break;
    case 'Chelan County':
    $chelan = 'chelan';
    break;
    case 'Clallam County':
    $clallam = 'clallam';
    break;
    case 'Clark County':
    $clark = 'clark';
    break;
    case 'Columbia County':
    $columbia = 'columbia';
    break;
    case 'Cowlitz County':
    $cowlitz = 'cowlitz';
    break;
    case 'Douglas County':
    $douglas = 'douglas';
    break;
    case 'Ferry County':
    $ferry = 'ferry';
    break;
    case 'Franklin County':
    $franklin = 'franklin';
    break;
    case 'Garfield County':
    $garfield = 'garfield';
    break;
    case 'Grant County':
    $grant = 'grant';
    break;
    case 'Grays Harbor County':
    $grays_harbor = 'grays harbor';
    break;
    case 'Island County':
    $island = 'island';
    break;
    case 'Jefferson County':
    $jefferson = 'jefferson';
    break;
    case 'King County':
    $king = 'king';
    break;
    case 'Kitsap County':
    $kitsap = 'kitsap';
    break;
    case 'Kittitas County':
    $kittitas = 'kittitas';
    break;
    case 'Klickitat County':
    $klickitat = 'klickitat';
    break;
    case 'Lewis County':
    $lewis = 'lewis';
    break;
    case 'Lincoln County':
    $lincoln = 'lincoln';
    break;
    case 'Mason County':
    $mason = 'mason';
    break;
    case 'Okanogan County':
    $okanogan = 'okanogan';
    break;
    case 'Pacific County':
    $pacific = 'pacific';
    break;
    case 'Pend Oreille County':
    $pend_oreille = 'pend_oreille';
    break;
    case 'Pierce County':
    $pierce = 'pierce';
    break;
    case 'San Juan County':
    $san_juan = 'san juan';
    break;
    case 'Skagit County':
    $skagit = 'skagit';
    break;
    case 'Skamania County':
    $skamania = 'skamania';
    break;
    case 'Snohomish County':
    $snohomish = 'snohomish';
    break;
    case 'Spokane County':
    $spokane = 'spokane';
    break;
    case 'Stevens County':
    $stevens = 'stevens';
    break;
    case 'Thurston County':
    $thurston = 'thurston';
    break;
    case 'Wahkiakum County':
    $wahkiakum = 'wahkiakum';
    break;
    case 'Walla Walla County':
    $walla_walla = 'walla walla';
    break;
    case 'Whatcom County':
    $whatcom = 'whatcom';
    break;
    case 'Whitman County':
    $whitman = 'whitman';
    break;
    case 'Yakima County':
    $yakima = 'yakima';
    break;
    }
    }
    }

    $last_updated = date('Y-m-d');

    $provider_name = escape_data($_POST['provider_name']);
    $contact_fname = escape_data($_POST['contact_fname']);
    $contact_lname = escape_data($_POST['contact_lname']);
    $phone = escape_data($_POST['phone']);
    $email = escape_data($_POST['email']);
    $url = escape_data($_POST['url']);
    $eligibility_req = escape_data(nl2br($_POST['eligibility_req']));
    $program_desc = escape_data(nl2br($_POST['program_desc']));
    $app_proc = escape_data($_POST['app_proc']);
    $deadline = $_POST['deadline'];

    $sql = "INSERT INTO providers (provider_name, contact_fname, contact_lname, phone, email, url, eligibility_req, statewide, adams, asotin, benton, chelan, clallam, clark, columbia, cowlitz, douglas, ferry, franklin, garfield, grantt, grays_harbor, island, jefferson, king, kitsap, kittitas, klickitat, lewis, lincoln, mason, okanogan, pacific, pend_oreille, pierce, san_juan, skagit, skamania, snohomish, spokane, stevens, thurston, wahkiakum, walla_walla, whatcom, whitman, yakima, el_all, el_cities_towns, el_county, el_state, el_federal, el_nat, el_nonprofit, el_private, el_individual, el_spd, el_other, sc_all, sc_grants, sc_loans_pri, sc_gloans, sc_ta, sc_other, description, app_procedures, last_updated, ced_all, ced_disaster, ced_bus_incubators, ced_historic_pres, ced_housing, ced_industrial, ced_nr, ced_pub_safety, ced_research, ced_rural_plan, ced_sust_dev, ced_urb_plan, ced_other, comm_all, comm_broadcast, comm_tele, comm_other, ed_all, ed_childcare, ed_k12, ed_he, ed_lib, ed_comm_ed, ed_research, ed_other, ener_all, ener_alt, ener_coal, ener_elec, ener_hydro, ener_nuclear, ener_solar, ener_wind, ener_other, ener_bio, env_all, env_ag, env_brownfields, env_ener_eff, env_forestry, env_grazing, env_green_bldg, env_landscaping, env_landuse, env_riparian, env_sp, env_other, pf_all, pf_art, pf_comm_centers, pf_ad_al, pf_fs, pf_ps, pf_pj, pf_pl, pf_health_fac, pf_mun_bldgs, pf_museums, pf_other, rec_all, rec_greenbelt, rec_outdoor, rec_parks, rec_sports, rec_trails, rec_other, rec_play, trans_all, trans_air, trans_bridges, trans_marine, trans_offroad, trans_pt, trans_ped_bike, trans_parking, trans_pub_lighting, trans_streets, trans_rail, trans_other, wm_all, wm_hazard, wm_recycling, wm_solid_waste, wm_waste_water, wm_other, water_all, water_dams, water_irr, water_storm, water_drinking, water_flood, water_other, pp_all, pp_planning, pp_feas, pp_design, pp_construction, pp_other, deadline) VALUES ('$provider_name', '$contact_fname', '$contact_lname', '$phone', '$email', '$url', '$eligibility_req', '$statewide', '$adams', '$asotin', '$benton', '$chelan', '$clallam', '$clark', '$columbia', '$cowlitz', '$douglas', '$ferry', '$franklin', '$garfield', '$grant', '$grays_harbor', '$island', '$jefferson', '$king', '$kitsap', '$kittitas', '$klickitat', '$lewis', '$lincoln', '$mason', '$okanogan', '$pacific', '$pend_oreille', '$pierce', '$san_juan', '$skagit', '$skamania', '$snohomish', '$spokane', '$stevens', '$thurston', '$wahkiakum', '$walla_walla', '$whatcom', '$whitman', '$yakima', '$el_all', '$el_cities_towns', '$el_county_gov', '$el_state_gov', '$el_fed_gov', '$el_nat', '$el_nonprofit', '$el_private', '$el_ind', '$el_spd', '$el_other', '$sc_all', '$sc_grants', '$sc_loans_pri', '$sc_g_loans', '$sc_ta', '$sc_other', '$program_desc', '$app_proc', '$last_updated', '$ced_all', '$ced_dr_aid', '$ced_bi', '$ced_hp', '$ced_housing', '$ced_ind_park', '$ced_nr', '$ced_ps', '$ced_research', '$ced_rural', '$ced_sd', '$ced_up', '$ced_other', '$comm_all', '$comm_bs', '$comm_tele', '$comm_other', '$ed_all', '$ed_childcare', '$ed_k12', '$ed_he', '$ed_lib', '$ed_ce', '$ed_rf', '$ed_other', '$en_all', '$en_ae', '$en_coal', '$en_elec', '$en_hydro', '$en_nuc', '$en_solar', '$en_wind', '$en_other', '$en_bio', '$env_all', '$env_ag', '$env_brown', '$env_ee', '$env_forest', '$env_grazing', '$env_gb', '$env_landscaping', '$env_lup', '$env_riparian', '$env_shoreline', '$env_other', '$pf_all', '$pf_art', '$pf_cc', '$pf_adal', '$pf_fire', '$pf_ps', '$pf_prisons', '$pf_pl', '$pf_hcf', '$pf_mb', '$pf_museums', '$pf_other', '$rec_all', '$rec_greenbelt', '$rec_or', '$rec_parks', '$rec_sports', '$rec_trails', '$rec_other', '$rec_playgrounds', '$trans_all', '$trans_air', '$trans_bridges', '$trans_marine', '$trans_ors', '$trans_pts', '$trans_pbf', '$trans_park', '$trans_pl', '$trans_streets', '$trans_rs', '$trans_other', '$wm_all', '$wm_hazard', '$wm_recycle', '$wm_sw', '$wm_wwss', '$wm_other', '$water_all', '$water_dams', '$water_irrigation', '$water_storm', '$water_drinking', '$water_flood', '$water_other', '$pp_all', '$pp_planning', '$pp_feas', '$pp_design', '$pp_construct', '$pp_other', '$deadline')";

    $result = @mysql_query($sql,$connection) or die(mysql_error());

    ?>

    <html>
    <head>
    <title>Record Added Successfully</title>
    <link rel="stylesheet" href="style/infra-db.css" type="text/css">
    </head>

    <body>

    <div class="header">
    <p class="title">Washington Infrastructure Database</p>
    <p class="subtitle">Record Added Successfully</p>
    <p class="links"><a href="show_add.php">Add Record</a> | Modify Record | <a href="pick_viewrecord.php">View Records</a></p>
    </div>

    <?php

    } else { header("Location: http://" . $_SERVER['HTTP_HOST'] .
    dirname($_SERVER['PHP_SELF']) . "/login.php");
    exit(); }?>

    </body>
    </html>

  8. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Sorry, but I'm gonna ask for one more thing before I get to work.
    Can I have an example? (Not needed, just curious and it helps).
    Also, when you put any kinda code use the [code] [/code] tags, when your using html use the [html] [/html] tags, and when your using php use the [php] [/php] tags.
    Jeremy | jfein.net

  9. #9
    Join Date
    Oct 2007
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm not sure what you mean by an example?

    Anyway, i've been playing with the code for awhile now. When i do a var_dump on the geo_scope[] array field which is the select box that was filled by clicking the add button on the show_add.php script i get NULL. I thought it was the javascript you gave me that was causing the problem but using the web developer toolbar for firefox, after adding several counties into the new select box it shows them accurately having the right values for each option.

    i also thought maybe the problem might be that the id and the name fields for the select boxes are different but i tried this with a text field and it didnt matter what i gave as the value for the id field the addrecord script still recognized it's value correctly.

    I don't know why the variable is coming out as NULL using var_dump()??

  10. #10
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Just to straighten this out, I thought that the value wasn't following the options when the javascript fixed it. So your saying that it passes the values correctly and it's the PHP? Try running it through print_r and see if you get the same results.
    Example as in an example page, the page that this script is on with the php.
    Jeremy | jfein.net

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •