SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Apr 2004
    Location
    UK
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Drop Menu with onChange to populate hidden input prior to submit

    I have the php code working to produce the drop menu and use the
    Code:
    onChange="flagmastcountryflag(this.value)"
    to pass the value to javascript for process.
    Code:
    <?php
    // Creates a pull-down list of flagmastcountries
      function get_flagmastcountry_list($name, $selected = '', $parameters) {
        $flagmastcountries_array = array(array('id' => '', 'text' => PULL_DOWN_DEFAULT_FLAGMASTCOUNTRY));
        $flagmastcountries = get_flagmastcountries();
    
        for ($i=0, $n=sizeof($flagmastcountries); $i<$n; $i++) {
          $flagmastcountries_array[] = array('id' => $flagmastcountries[$i]['countries_id'], 'text' => $flagmastcountries[$i]['countries_name']);
        }
    
        return draw_pull_down_menu($name, $flagmastcountries_array, $selected, $parameters);
      }
    
      function get_flagmastcountries($flagmastcountries_id = '', $with_iso_codes = true) {
        $flagmastcountries_array = array();
    
          $flagmastcountries = tep_db_query("select countries_id, countries_name from " . TABLE_FLAGMASTCOUNTRIES . " order by countries_name");
          while ($flagmastcountries_values = tep_db_fetch_array($flagmastcountries)) {
            $flagmastcountries_array[] = array('countries_id' => $flagmastcountries_values['countries_id'],
                                       'countries_name' => $flagmastcountries_values['countries_name']);
    
        }
    
        return $flagmastcountries_array;
        }
     	echo get_flagmastcountry_list('flagmastcountry','','onChange="flagmastcountryflag(this.value);"'); ?>
    Which I then need to populate the hidden input at the point $flagmastcountryflag
    Code:
                $tmp_html = '<input type="hidden" name ="id[' . TEXT_PREFIX . $products_options_name['products_options_id'] . ']" size="' . $products_options_name['products_options_length'] .'" maxlength="' . $products_options_name['products_options_length'] . '" value="' . $cart->contents[$HTTP_GET_VARS['products_id']]['attributes_values'][$products_options_name['products_options_id']] . $flagmastcountryflag .'">';
    
    echo             '<td class="main">' . $tmp_html . '</td>';
    Javascript needed
    Code:
    function flagmastcountryflag() {
    this where the help is needed how code the function to pass the value of (this.value) and output.

  2. #2
    SitePoint Member
    Join Date
    Apr 2004
    Location
    UK
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I now have this for the javascript function
    Code:
    function flagmastcountryflag() {
      if(document.cart_quantity.flagmastcountry.options[0].value == true) {
        return false
      }
      else {
    document.cart_quantity.idtxt_21.value=document.cart_quantity.flagmastcountry.options[document.cart_quantity.flagmastcountry.selectedIndex].text;
      }
      return true;
    }
    this works provided I change the php side to give the input field name idtxt_21, however I need the name to be id[txt_21] for later in the php process.

    How do I get the javascript to work using id[txt_21] instead of idtxt_21


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
  •