Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

how to pull id from dynamic select


steveh1

Recommended Posts

Posted

in the product_info page in the root of the catalog there is the following

 

<?php echo tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute); ?>

 

I know it draws out 2 dropdown menus with ids and attributes that are pulled form the products attribute...I know not how...but what I would like to do is to have each pull down menu push out there ids in seperate variables.

 

Anyone know how? please

steve

Posted

the product options have different values. There is a loop that iterates through the attributes assigned for the products and outputs one pull-down for each option with all the values assigned. Those are picked up from the database (and can be adjusted from your osc admin->Catalog->Product Attributes)

  • 2 weeks later...
Posted

Thanks for the reply and appologies for the delay...I have been away.

 

So, i know there is a loop that pushes two drop down boxes...1 is length and one is of width (length contains 1-30) and width 2 different sizes.

what I need to do is detect the select(id) of both as they are pushed out then have some php or javascript pull in the contents of each selected item ready for a pricing calculation...see the following and the additional calculate before you buy button at the bottom which I have 'plumbed in'...at the moment pulling in the base price and pushing that out...so that works...it the rest I have difficulties with...see

 

http://www.sureguard.co.uk/catalog/product...;products_id=28

 

So to reiterate....I want a user to be able to calculate a length of material by 'PRESSING' the calculate button and NOT having to mentally add up the base price then multiply the extra costs for length and then add an xtra £5 if they choose the larger width opition...more of a TRY BEFORE YOU BUY COSTING/S really

 

cheers

steve

Posted

see how the popup image code in the product_info.php page handles the popup. (using a different script popup_image.php)

 

Ok now your new popup could simply display the result of this calculation. Basically your new button will change the form to be submitted to the new popup instead of the cart redirect with all the selected parameters. That is one way.

 

Another will be to handle everything in application_top.php for form submission and based on the button pressed to identify where to redirect. And another will be to use only jscript for this and update a visible field in the product info page.

 

The variables you need (and you have)

$products_options['products_options_values_id']

$products_options['options_values_price']

 

The first you have it as the selected value when you submit the form (for each of the pull-downs). The 2nd can be derived again in the popup code for instance because you have the id.

Posted

ok ...checked that...I can get the ids as it pushes them by echo-ing out the following

 

echo $products_options_name['products_options_id']

 

However, I have tried to get the a value by using the following javascript code - with which the calculation will be handled

 

item_price2 = document.getElementById("id[4]").value;

document.getElementById("total").innerHTML = item_price2;

 

NOTE: I get a javascript error: document.getElementById("id[4]") has no properties - by watching it via a javscript console in firefox.

 

Where is the function tep_draw_pull_down_menu in the site/php? I need to assign id as an attribute to the menus so I can use getElementById...at the moment it only pushes out Name as a select attribute.

 

cheers

steve

Posted

You mean you want to do it without page reloading? (meaning he changes a selection from the drop-down list and the jscript updates another field)

 

If so you need to detect the selected index when you use jscript and update this other field. And you should use getElementsByName for this.

 

The function btw is in catalog\includes\functions\html_output.php

but you don't need it. The drop-down list name you have it in your product_info.php is the one you're already using.

Posted

ok great...got the value from one of the selects....

 

one problem still exists...the select <option value></option> is populated via the database which results in

 

<option value="7">1</option> //7 being the id

<option value="8">2 (+£14.93)</option> //8 being the id

 

as an example.

 

The data I really need is the physical 1 or 2 strings wrapped by the <option></option> tags. Any ideas?

 

I will seperate any data after the figure value say the (+£14.93) by using javascript split.

 

many thanks for the help and assistance

 

steve

Posted

I suppose I could just edit the db to reflect the integers needed 1 to 30 for lengths and then apply my calculation for price and discounts.

 

What would you do? (remember i am quite new-ish to php and oscommerce)

 

rgds

steve

Posted

ok, simpler than that....I used an offset figure of 6.

 

So, because any product with lengths attached as attributes will always ( I assume) have the same ids attached as length so i can always use a default offset figure of 6 to subtract away from the id value (being that the Db ids start at 7 throught to 36 for lengths 1 to 30).

 

I bet I find another problem...oh well onwards!

 

cheers

steve

Posted

you will retrieve the data after you locate the selected index from the drop-down list. See how this contribution uses the selected index from a drop-down list and sets a text area.

http://www.oscommerce.com/community/contributions,4238

Once you extract the files open readme.htm, read item-7 the jscript function called comboToArea. File pdf_mysql_report.php uses the jscript function to post the selection into the text area.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...