Guest Posted November 13, 2004 Posted November 13, 2004 Howdy all, I have been working for ages to get a java script to work with options as images. This is from the priceupdater v3 contribution. It uses a js (see below) to do the work. When I don't have options as images active everything runs just fine, and the prices update accordingly. But when I activate options as images nothing shows. I tried to just put the js in the options_images.php file, but that doesn't work. I then thought that if I moved the js out of the product_info.php file and just said (include option.js) in the top it would work..but no go. It works just fine w/o options as images running. Does anyone know how I can get the js to run in the options_images.php file? Below are the options_images.php file and the js. Any help would be great, THANKS! RavenWulf <?php /* $Id: options_images.php,v 1.0 2003/08/18 osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License */ $products_attributes_query = tep_db_query("select count(*) as total from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'"); $products_attributes = tep_db_fetch_array($products_attributes_query); if ($products_attributes['total'] > 0) { ?> <table border="0" cellspacing="0" cellpadding="2"> <tr> <?php echo '<td class="main" colspan="2">' . TEXT_PRODUCT_OPTIONS . '<br>Please select your desired option using the buttons provided'; ?> <?php if (OPTIONS_IMAGES_CLICK_ENLARGE == 'true') echo '<br>Click the images to enlarge';?> </td> </tr> <?php $products_options_name_query = tep_db_query("select distinct popt.products_options_id, popt.products_options_name, popt.products_options_sort_order, popt.products_options_images_enabled from " . TABLE_PRODUCTS_OPTIONS . " popt, " . TABLE_PRODUCTS_ATTRIBUTES . " patrib where patrib.products_id='" . (int)$HTTP_GET_VARS['products_id'] . "' and patrib.options_id = popt.products_options_id and popt.language_id = '" . (int)$languages_id . "'" . " order by popt.products_options_sort_order"); while ($products_options_name = tep_db_fetch_array($products_options_name_query)) { $products_options_array = array(); $products_options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_name, pov.products_options_values_thumbnail, pa.options_values_price, pa.price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pa.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pa.options_id = '" . (int)$products_options_name['products_options_id'] . "' and pa.options_values_id = pov.products_options_values_id and pov.language_id = '" . (int)$languages_id . "'order by pa.products_options_sort_order"); while($products_options = tep_db_fetch_array($products_options_query)){ $products_options_array[] = array('id' => $products_options['products_options_values_id'], 'text' => $products_options['products_options_values_name'], 'thumbnail' => $products_options['products_options_values_thumbnail']); if ($products_options['options_values_price'] != '0') { $products_options_array[sizeof($products_options_array)-1]['text'] .= ' (' . $products_options['price_prefix'] . $currencies->display_price($products_options['options_values_price'], tep_get_tax_rate($product_info['products_tax_class_id'])) .') '; } } if (isset($cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']])) { $selected_attribute = $cart->contents[$HTTP_GET_VARS['products_id']]['attributes'][$products_options_name['products_options_id']]; } else { $selected_attribute = false; } ?> <tr> <td class="main" valign="top"><?php echo $products_options_name['products_options_name'] . ':'; ?></td> <?php if ($products_options_name['products_options_images_enabled'] == 'false'){ echo '<td class="main">' . tep_draw_pull_down_menu('id[' . $products_options_name['products_options_id'] . ']', $products_options_array, $selected_attribute, "onChange='showPrice(this.form);'") . '</td></tr>'; } else { $count=0; echo '<td class="main"><table><tr>'; foreach ($products_options_array as $opti_array){ echo '<td><table cellspacing="1" cellpadding="0" border="0">'; if (OPTIONS_IMAGES_CLICK_ENLARGE == 'true') echo '<td align="center"><a href="javascript:popupWindow(\'' . tep_href_link(FILENAME_OPTIONS_IMAGES_POPUP, 'oID=' . $opti_array['id']) .'\')">' . tep_image(DIR_WS_IMAGES . 'options/' . $opti_array['thumbnail'], $opti_array['text'], OPTIONS_IMAGES_WIDTH, OPTIONS_IMAGES_HEIGHT, 'class=shadow1') . '</a></td></tr>'; else echo '<tr><td align="center">' . tep_image(DIR_WS_IMAGES . 'options/' . $opti_array['thumbnail'], $opti_array['text'], OPTIONS_IMAGES_WIDTH, OPTIONS_IMAGES_HEIGHT) . '</td></tr>'; echo '<tr><td class="main" align="center">' . $opti_array['text'] . '</td></tr>'; if (($selected_attribute == false && $count == 0) || ($selected_attribute == $opti_array['id'])) { echo '<tr><td align="center"><input type="radio" name ="id[' . $products_options_name['products_options_id'] . ']" value="' . $opti_array['id'] . '" ></td></tr></table></td>'; } else { // this line when get js script to work echo '<tr><td align="center"><input type="radio" name ="id[' . $products_options_name['products_options_id'] . ']" value="' . $opti_array['id'] . '" onChange="'.showPrice(this.form).'"></td></tr></table></td>'; echo '<tr><td align="center"><input type="radio" name ="id[' . $products_options_name['products_options_id'] . ']" value="' . $opti_array['id'] . '" ></td></tr></table></td>'; } $count++; if ($count%OPTIONS_IMAGES_NUMBER_PER_ROW == 0) { echo '</tr><tr>'; $count = 0; } } echo '</table>'; } ?> </td></tr> <?php } ?> </table> <?php } ?> around line 66 you can see where I changed it to call to the js. I just need the darn js to run. <script language="javascript"> <!-- function FormatNumber(num) { if(isNaN(num)) { num = "0"; } sign = (num == (num = Math.abs(num))); num = Math.floor(num*100+0.50000000001); cents = num%100; num = Math.floor(num/100).toString(); if(cents<10) { cents = "0" + cents; } for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) { num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3)); } return (((sign)?'':'-') + num + '.' + cents); } function showPrice(form) { var myTotalPrice = 0; var showUP = 0; var myMathProblem = ""; myItemPrice = parseFloat(form.nuPrice.value); for (var i = 0; i < form.elements.length; i++) { var e = form.elements[i]; if ( e.type == 'select-one' ) { showUP = 1; Item = e.selectedIndex; myPrice = e.options[Item].text; myDollarSign = myPrice.indexOf("$",0) if ( myDollarSign != "-1" ) { myParSign = myPrice.indexOf(")", myDollarSign); myAttributeString = myPrice.substring(myDollarSign+1, myParSign); myAttributeString = myAttributeString.replace(/,/,""); myAttributePrice = parseFloat(myAttributeString); myMathProblem = myPrice.charAt(myDollarSign - 1); } else { myAttributePrice = 0; } if (myMathProblem == "-") { myTotalPrice = myTotalPrice - myAttributePrice; } else { myTotalPrice = myTotalPrice + myAttributePrice; } } } if ( showUP ) { myTotalPrice = FormatNumber(myTotalPrice + myItemPrice); document.getElementById("productNEWprice").innerHTML = "Subtotal Price with Options $" + myTotalPrice; } } //--> </script> Quote
Jan Zonjee Posted November 13, 2004 Posted November 13, 2004 Why is the showPrice(this.form) treated as a PHP variable (like: '. $variable .')? onChange="'.showPrice(this.form).'" Perhaps changing it to: onChange="showPrice(this.form)" would work? Quote
Guest Posted November 13, 2004 Posted November 13, 2004 hmm I'll have to try that. Thanks! Oh and I guess the answer to your question is because I am a still learning php,mysql, etc.. :blush: RavenWulf Why is the showPrice(this.form) treated as a PHP variable (like: '. $variable .')? onChange="'.showPrice(this.form).'" Perhaps changing it to: onChange="showPrice(this.form)" would work? <{POST_SNAPBACK}> Quote
Guest Posted November 13, 2004 Posted November 13, 2004 Thanks for the info, I tried it out, and at least now I am not getting any error messages. But I am still not seeing the price update js show when I enable options as images. RavenWulf Why is the showPrice(this.form) treated as a PHP variable (like: '. $variable .')? onChange="'.showPrice(this.form).'" Perhaps changing it to: onChange="showPrice(this.form)" would work? <{POST_SNAPBACK}> Quote
Jan Zonjee Posted November 13, 2004 Posted November 13, 2004 I'm not much of a programmer myself and JavaScript is a programming language I think is more difficult than PHP, but for what it is worth: I couldn't find any <form name="bla" action="needed?" onSubmit="needed?">code, code, code </form>. You call the elements of the form with showPrice(this.form) but no form element is on the page (I couldn't find it in the code you showed anyway). My reasoning would be that if there is no form tag with a name, there is no form elements array, end of story for JavaScript. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.