PDA

View Full Version : modifying a dynamic menu script to accept two capital letters


canadianjameson
02-08-2005, 07:05 PM
for those of you who know me, you'll recognise this.


function refill_Product(objProducer) {
var objProduct = objProducer.form.Product;
var selectedArray = window[objProducer.options[objProducer.selectedIndex].value.replace(/\s/g,'') + "_Array"];
objProduct.options.length = 0;
for (var i=0; i < selectedArray.length; i++) {
objProduct.options[i]=new Option(selectedArray[i], selectedArray[i].replace(/->\s/g, ""));
}
}


i need to modify it to accept an entry with TWO capital letters in it. right now i think it strips them out before sending them to another script to be used to populate a second menu based on the first selection. i think it only looks at the first letter.. however i now have a name that has 2 in it and the script crashes going from:


This:
var Scaletron_Array = new Array("Now please select the desired product","--------------------------->","Silo Weighing - Strain Guages","Silo Weighing - Load Cells","...");

To this:
var ScaleTron_Array = new Array("Now please select the desired product","--------------------------->","Silo Weighing - Strain Guages","Silo Weighing - Load Cells","...");


how do i modify the script to allow the change?

Willy Duitt
02-08-2005, 10:30 PM
Why are you changing the variable name??

canadianjameson
02-10-2005, 05:37 AM
Because the variable name is what is taken by the script and displayed in the dropdown menu, and ultimately on the quote itself.

the company in question's encorporated name is ScaleTron, and they contacted me and asked me if it were possible to modify the script so that the quotes the receive via the page show their proper company name.

I could say no and that would be the end of it, i just figured there may be an easy way to fix this, like a mini character place counting loop or something

just me being difficult Willy :D

Willy Duitt
02-10-2005, 06:19 AM
I see absolutely no rhyme or reason to be changing the variable name... If you do, I'm sure there are numerous places in the script which will need to be modifed... If I recall, when we first helped you with this script if was written in such a way that it can be used on multiple selects and was not specific to any particular form element ( OOP )... However, I could be wrong...

But, from what I see your problem evolves around removing the -> you had previously placed in your selects and which required stripping out in order to pass the select text as a value to your function...

selectedArray[i].replace(/->\s/g, ""));

And it appears the problem is now you are also trying to hyphenate a company name and these hyphens are being stripped out as well...

Try changing the above to:
selectedArray[i].replace(/-(?=>)\s/g, "").replace(/>/g,''));

Hopefully, if I understand the problem correctly, this should strip out only those hyphens which are followed by a >, spaces and return to strip out the >...

.....Willy

Edit: Oh forget that _____^
I just reread your reply and I now understand that this is a minor thing which I myself would be loathe to bother with... Try making a copy and use global search and replace to change scaletron to scaleTron... Should not be that difficult....

canadianjameson
02-10-2005, 08:11 PM
I'll give it a shot

Thanks Willy