Jump to content


Corporate Sponsors


Latest News: (loading..)

* * * * * 3 votes

How to create a drop down selection menu


58 replies to this topic

#41 spooks

  • Community Member
  • 7,017 posts
  • Real Name:Sam
  • Gender:Male
  • Location:UK

Posted 21 January 2010, 11:56

View Posttjc0ol, on 21 January 2010, 06:57, said:

Hello all there,

A newbie here. Is there any chance that the dropdown menu in the admin/orders.php which handles the order statuses could be translated to a radio buttons? So if anyone process the orders, you can just hit the radio button (with pending, processing or shipped) will be displayed.

-Tj


If your wanting to write some code, look at the existing & see what you can do yourself, post your issues if you have problems. [img]http://forums.oscommerce.com/public/style_emoticons/default/wink.gif[/img]

If your expecting someone else to write some code for you for free, your expecting too much from the forum!! [img]http://forums.oscommerce.com/public/style_emoticons/default/ohmy.gif[/img]
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#42 xecutech

  • Community Member
  • 85 posts
  • Real Name:Tom Featherstone
  • Gender:Male
  • Location:Nashville

Posted 02 February 2010, 22:45

I am trying to get oscommerce to do something similiar to this site's drop down menus for each product. I have looked through several conreibutions, and not finding anything close that is working, or still be supported.

http://www.oemheaters.com/product/tabid/60/productid/86/sename/heavy-extra-heavy-duty-drumpail-heaters/default.aspx

I know this site was done in asp. I was thinking if a drop down menu for the main product would call the items from a category, with an option to add how many items, and add to cart button would be good. Then I can use the category hide contribution?

I may be overlooking something else that would work, so any advice would be greatly appreciated.

Thank you.

#43 spooks

  • Community Member
  • 7,017 posts
  • Real Name:Sam
  • Gender:Male
  • Location:UK

Posted 16 March 2010, 21:05

View Postxecutech, on 02 February 2010, 22:45, said:




Your looking at something quite different, this thread is about standard osC drop down's, like the maunufacturer or atribute selections, your talking of menu's, the menu u link to is actually badly done with javascript, but could easily be done with css, look for css menu contribs.
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#44 RyGoTypE

  • Community Member
  • 7 posts
  • Real Name:Mike

Posted 26 April 2010, 02:02

Question --

How would I go about adding an if statement to a drop down?

Default Selected option -- Please Select
Option 1 -- Yes
Option 2 -- No

If user selects yes, add a new label and text box underneath the current label and drop menu.

If user selects no, do nothing.

My current array looks like:

      <?php 
        $some_array = array();
        $some_array[0] = array('id' => '0', 'text' => 'Please Select');
        $some_array[1] = array('id' => '1', 'text' => 'Yes');
        $some_array[2] = array('id' => '2', 'text' => 'No');
      ?>

Not sure how to go with this if statement though.

Tags: if statement php array drop menu pull down tep_draw_pull_down_menu

Edited by RyGoTypE, 26 April 2010, 02:04.


#45 spooks

  • Community Member
  • 7,017 posts
  • Real Name:Sam
  • Gender:Male
  • Location:UK

Posted 26 April 2010, 13:39

View PostRyGoTypE, on 26 April 2010, 02:02, said:

How would I go about adding an if statement to a drop down?


If user selects yes, add a new label and text box underneath the current label and drop menu.

If user selects no, do nothing.



I think your saying u want to update the page content dynamically without refreshing the page, to do that you have to use ajax (ie javascript) look at those methods, but remember to allow for visitors that have scripts off.

To change any page coontent with pure php you have to reload the page, ie set and compare a var.
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#46 dcor

  • Community Member
  • 4 posts
  • Real Name:David

Posted 27 May 2010, 20:46

View Postspooks, on 28 August 2009, 22:27, said:

This is the standard method used by osC for all pull downs, so to see an example just look at any pull down from a official distribution (ie manufacturers on home page etc).

Please note, often template writers have no clue how this is supposed to work, so pull downs in templates are often severely hacked (and bugged), so ignore them.
Hi
I am new to this forum, and relatively new to OS Commerce. I've taken on this project to create my ecommerce website, and decided to go with OS Commerce. I've been reading various sources to educate myself on how to tweak OS Commerce. To speed up the design of my site, i decided to purchase a template. I've been able to tweek it for the most part. However, I am now stuck. In the original OS Commerce v2.2 RC2 distribution, a drop down box for choosing the manufacturer shows up in the subcategory (DVD Movies -> Action (9). My template does not show this drop down menu, and it's been driving me crazy trying to find where this may be in the original distribution so that I can try and recreate it in my template. Any help pointing me to this direction would be appreciated. I will post an image to show the drop down menu I am referring to... on second thought I cant seem to upload an image file here... Thanks,

#47 dcor

  • Community Member
  • 4 posts
  • Real Name:David

Posted 28 May 2010, 18:43

View Postdcor, on 27 May 2010, 20:46, said:

Hi
I am new to this forum, and relatively new to OS Commerce. I've taken on this project to create my ecommerce website, and decided to go with OS Commerce. I've been reading various sources to educate myself on how to tweak OS Commerce. To speed up the design of my site, i decided to purchase a template. I've been able to tweek it for the most part. However, I am now stuck. In the original OS Commerce v2.2 RC2 distribution, a drop down box for choosing the manufacturer shows up in the subcategory (DVD Movies -> Action (9). My template does not show this drop down menu, and it's been driving me crazy trying to find where this may be in the original distribution so that I can try and recreate it in my template. Any help pointing me to this direction would be appreciated. I will post an image to show the drop down menu I am referring to... on second thought I cant seem to upload an image file here... Thanks,
Looks like I found the culprit. It's in the index.php file under //optional product list filter. Apparently mine was enclosed with this - /* */

Now that I've removed the, my template format is out of whack... : (

#48 kycnotes

  • Community Member
  • 77 posts
  • Real Name:Brennan

Posted 30 June 2010, 17:14

Hello,

This drop down works very well, but I have one question. How do you set the maximum category value, ie. in the admin section of OSc, you can set the maximum value for the number of characters that will be displayed in the manufacturer's box. Can this be done with the category drop down? I know I am missing something here, as this doesn't seem too complicated. Any help is greatly appreciated.

Thanks,

B.

#49 edensan

  • Community Member
  • 22 posts
  • Real Name:Edwin

Posted 14 July 2011, 21:01

Hi Sam and al the ppl out here,

is it possible to make a dropdown button for customers to select a pickup day in the shipping section during checkout?
so custumor select cash on pickup and come to shop on (dropdown menu) monday thuesday etc. etc.
i will be verry happy if i would have that option.

greetz Edwin

#50 ingharic

  • Community Member
  • 3 posts
  • Real Name:Richard Ingham

Posted 15 July 2011, 11:16

Hi,

I have read your drop down selection menu. www.winningcolours.co.uk want an option where when the customer makes a selection it changes the image as they go along so they can see what they are purchasing. The site has been setup using OS commerce. Do you have any ideas how I do this?

Regards

Richard

View Postspooks, on 08 August 2009, 11:29, said:

People often ask how to create a drop down selection menu for some item, they often seem to struggle coming up with some weird coding or attempt with pure html.

osC includes a function tep_draw_pull_down_menu which I will use, this removes much of the coding but requires a correctly formatted multi-dimensional
array, this is the achilles heel for many, preventing them using the function.

The parameters for tep_draw_pull_down_menu are ($name, $values, $default = '', $parameters = '', $required = false)

$name is the id for the field
$values is the array containing the selection data
$default is the default value selected
$parameters optional styling params
$required adds the defined TEXT_FIELD_REQUIRED text if true

For this example I will use code I created for a links categories pull down menu for my reciprocal links contrib.


Step one: create array & put default values

//category drop-down
  $category_array = array();
  $category_array[0] = array('id' => '0', 'text' => 'Please Select');

Step two: read data from dBASE for use in array

$category_query = tep_db_query("select category_id, category_name from links_categories where status = 1 order by sort_order, category_name");

Step three: loop through the data, placing it into the selection array ($category_array)

 while ($category_values = tep_db_fetch_array($category_query)) {
	$category_array[] = array('id' => $category_values['category_id'], 'text' => $category_values['category_name']);
	   }

Note the use of 'id' & 'text', 'id' contains the values returned on selection, 'text' is what's displayed by the drop down (these can be the same).
Remember this array has its own index, it is not indexed by 'id'.

Step Four: Output the drop down!!

<td align="right" width="100%"><?php echo tep_draw_form('category', tep_href_link('links.php', 'action=catsel'), 'get').'Links Category: ' . 
tep_draw_pull_down_menu('select_category', $category_array, $selected_cat, 'onchange="this.form.submit();" rel="nofollow"'); ?>
<noscript><input title="View" name="" type="submit" value="Go" /></noscript></form></td>

In this case the drop down is within its own form (drop_downs must always be part of a form), if you are using this as part of a bigger form you can
remove the form elements.

Note the use of tep_href_link in the form action, this is critical.

Links Category: is the displayed text adjacent the drop.
'select_category' is the field id.
$category_array we created above.
$selected_cat has the currently selected category (so that shows pre-selected in the drop (the default))
'onchange="this.form.submit();"' a parameter, in this case a bit of JavaScript to accept input as soon as change made (just an option).
rel="nofollow" often useful to prevent issues with google (duplicate content) this will prevent validation though, use a canonical tag if that's an
issue (just an option).
<noscript><input title="View" name="" type="submit" value="Go" /></noscript> provide a submit button if scripts are off (just an option) Finally you must process the data at the receiving page, IE
$selected_cat = ($_GET['select_category'] > 0 ? $_GET['select_category'] : false);
this can be the same page if that's where your form action points.
You may wish to access the data in the selection array separately, this will be an issue as the array has its own index, so placing the same data in a second
array at the same time you create the selection array is the answer, IE within the while loop add:

$categories[$category_values['category_id']] = $category_values['category_name'];

You can now get any category by its id with
echo $categories[$id];

I think I`ve covered it all there, no doubt issue will arrise though.


#51 gfasal

  • Community Member
  • 342 posts
  • Real Name:George
  • Gender:Male
  • Location:Sevilla, Spain

Posted 20 July 2011, 13:09

A big thanks for this, you have answered my question!
OSC 2.3.1
INSTALLED:Document Manager / Monthly Sales and Tax Returns / Batch Print Invoices / Ultimate HTML EMAILs / AJAX Attribute Manager / OSC PDF Catalog / Move Bookmarks / Sort Order / Easy Populate / Sales Reports / Low Stock Report / Admin: Model # on Category / Product Administration Screen / Mini images in admin / SLiCK reCaptcha / Google + / Beautiful Breadcrumbs / 2.3.1 - Banner Language Mod / ADD New Page / EASY MAP (google) v.3.0 / Who's Online Enhancement for 2.3.1 / Admin Notes / scrambled order number / remove_unused_images / Quantity Select / Unit Weight / Product Specifions (filter results) / AJAX Product Attributes/ Attribute Codes/ Date & Order No. to Invoice/ O.P.I. 2.0 / Attribute Images / Manual Order Editor / Attributes Clone / Order Editor / Create Order / Company VAT No. / Add customer/ CKEditor 2.3.1 / Page Manager / Default images via admin / Percentage Shipping Price / QTPro / Scroll to Top / PDF Invoice / Featured Products / Product Listing Enhancements / AutoBackups / ..Custom Admin Mods /

#52 nobodyfamous

  • Community Member
  • 78 posts
  • Real Name:Chad Meyers

Posted 16 January 2012, 17:08

thanks for this!!

#53 breakbred101

  • Community Member
  • 27 posts
  • Real Name:Eric

Posted 23 March 2012, 18:07

Nice tut, been hungup for hours on this thing any help be greatly appreciated.

So, I cant seem to get this damn drop down menu to pass the values to the intended table field.

My store services only a select few zip codes locally. Because most people dont like reading I have a lot of signups for out of area customers who then get upset when they order because "my site let them order" and have to call and refund them.

So I figure, I'll build a table "zipcodes" populate it with "zipcodes_id, zipcodes_number, status" fields. Set all statuses to (1) for active and not set a key. I assume i can reassign the variables in create_account.php to make this task even as troubless as possible. Well, not so easy so thanks for this spook, very helpful and educational. I understand every scenario is different but I'm assuming this is a typical osC drop_down_menu so the steps should be relatively the same. This form is also part of the create_account.php so I'm assuming i deleted the form properties correctley.

So I build my array,
//postalcode drop-down
  $zipcodes_array = array();
  $zipcodes_array[0] = array('id' => '0', 'text' => 'Please Select');
	  $zipcodes_query = tep_db_query("select zipcodes_id, zipcodes_number from " . TABLE_ZIPCODES . " where status= 1");
		
		while ($zipcodes_values = tep_db_fetch_array($zipcodes_query)) {
		$zipcodes_array[] = array('id' => $zipcodes_values['zipcodes_id'], 'text' => $zipcodes_values['zipcodes_number']);
		   }
?>
			 <tr>
				   <td class="main"><?php echo ENTRY_POST_CODE; ?></td>
				   <td class="main"><?php echo tep_draw_form('postcodes', tep_href_link('create_account.php', 'action=select'), 'get') .
tep_draw_pull_down_menu('zipcodes_numbers', $zipcodes_array, $selected_zip, 'onchange="select();" rel="nofollow"') . '&nbsp;' . (tep_not_null(ENTRY_POST_CODE_TEXT) ? '<span class="inputRequirement">' . ENTRY_POST_CODE_TEXT . '</span>': ''); ?></td>
The array renders ok, with this code, just as desired. But any selections that are made and submitted are not passed into any database tables or fields. What I'm trying to get is the "text" value inserted into the postcode field of address_book and not necessarily the zipcode_id

So I implement what I think is correct,
$selected_zip = tep_db_prepare_input($HTTP_POST_VARS['postcode']);
			$selected_zip = ($_GET['select_zipcodes'] > 0 ? $_GET['select_zipcodes'] : true);
Im translating this as the variable $selected_zip which i believe i have assigned in my array is going to be placed into the postcode field in the adress_book table after it $GET's the selected zipcodes either A. Id or B.Text value. Either one would be informitive at this point...

After implementation of this It will pass a value of 1 through to the postcode field despite which of my 32 options i picked, :unsure:

I have also changed,
 $customer_id = tep_db_insert_id();

	  $sql_data_array = array('customers_id' => $customer_id,
							  'entry_firstname' => $firstname,
							  'entry_lastname' => $lastname,
							  'entry_street_address' => $street_address,
							  'entry_postcode' => $selected_zip,
							  'entry_city' => $city,
							  'entry_country_id' => $country);


It was throwing the Zipcode must contain * characters on submit, so I ignored that and the form submits, just dosnt pass along. I've learned so much playing with this menu, but I'm tapped out if anyone can offer some assistance or direction please do.

Edited by breakbred101, 23 March 2012, 18:10.


#54 breakbred101

  • Community Member
  • 27 posts
  • Real Name:Eric

Posted 23 March 2012, 19:16

It's also my understanding that the pull_down call is still within a form field even though there is no closing tag

#55 spooks

  • Community Member
  • 7,017 posts
  • Real Name:Sam
  • Gender:Male
  • Location:UK

Posted 24 March 2012, 00:30

I see a number of issues, but to answer your last, yes the pull down must be part of a form & the form MUST be closed (with </form>)

You seem to be confusing $_POST & $_GET

If the form method is GET then only $_GET vars are set, there will be no $_POST vars

If the form method is POST then $_POST vars will be set but some $_GET vars can also be set via the uri used in the form link, i.e. you have
tep_href_link('create_account.php', 'action=select'

the action=select is part of the uri so is a $_GET var

Next problem, you have named your select field zipcodes_numbers but you trying to retrieve the data by referring to select_zipcodes

you must be consistent or things will not work

Some other points:

you've named your form postcodes that's fine as long as no other form with that name exists on the page, you do not need to refer to the form name at all when retrieving data.

your using $HTTP_POST_VARS which is depreciated always use $_POST and again be consistent, it is possible that $HTTP_POST_VARS & $_POST contain different data

Edited by spooks, 24 March 2012, 00:32.

Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#56 breakbred101

  • Community Member
  • 27 posts
  • Real Name:Eric

Posted 27 March 2012, 08:07

Thanks for taking the time to help spooks. It's much appreciated, I'm still pretty green to the concepts involved with PHP & $GET & $POST methods. The concept and rules involved with php seem to be above my grasp. I foudn it easier to go ahead and implement your hard coded method, wich seems to accomplish my job relatively easily considering i only have 32 zip codes to worry about. I figure it will be just as easy to update the hard coded zipcodes, as it would be to add a new row into the database.

You mentioned use $POST instead of $HTTP_POST_VARS, through out all my readings I have never stumbled across this recommendation ... It seems my entire site uses this syntax, would you recommend a site wide find & replace of all $HTTP_POST_VARS to $POST???

#57 spooks

  • Community Member
  • 7,017 posts
  • Real Name:Sam
  • Gender:Male
  • Location:UK

Posted 27 March 2012, 10:41

@breakbred101

Yes I am surprised to see that even in 2.3.x the depreciated vars appear even though they have long been so (since php 4.1) http://www.abdn.ac.uk/local/php/doc/reserved.variables.post.html

osC get around this issue with compatibility.php which references $HTTP_POST_VARS to $_POST and so on.

My advise, whenever you come to edit a page make it a practice to replace all the depreciated vars, it saves work with issues that may arise as php upgrades
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.

#58 al3ks

  • Community Member
  • 108 posts
  • Real Name:Aleksander
  • Gender:Male

Posted 06 April 2012, 01:04

How about if I want to change a drop down menu into a list with scroll bar, is it possible? What call function can I use?

#59 spooks

  • Community Member
  • 7,017 posts
  • Real Name:Sam
  • Gender:Male
  • Location:UK

Posted 11 April 2012, 00:24

@al3ks

You would not need any function, just create a series of links on separate lines within a limited height div and adjust your css
Sam

Remember, What you think I ment may not be what I thought I ment when I said it.

Contributions:


Auto Backup your Database, Easy way

Multi Images with Fancy Pop-ups, Easy way

Products in columns with multi buy etc etc

Disable any Category or Product, Easy way

Secure & Improve your account pages et al.