Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help finishing this script sorta

Status
Not open for further replies.

RogueDogg1

Programmer
Jul 13, 2006
11
US
Code:
function showDescription(sel, productdesc, price, productname){
    var opt = sel.options;
    if(opt[sel.selectedIndex].value == "productname"){
        productname.value = "product name";
		productdesc.value = "product description";
        price.value = "product price";
    }else{
		var ary = opt[sel.selectedIndex].value.split("|");
        productdesc.value = ary[0];
        price.value = ary[1];
		productname.value = ary[2];
    }
    return true;
}

So basically what this is doing is:
I have made a db query to get the (productname, productdesc, price) so I put the productname in a drop down menu from Dreamweaver and when you select a productname it will display the productdesc in a textarea and the price in a textbox.

Now that is working just fine, the problem is when I submit those values in the form and echo them the $productname doesn't display, it comes ends up displaying the productdesc | price -- productdesc again. So where might I be going wrong? I have a live working example if someone would like further testing just let me know. Thanks in advance for any help that would be given.
 
Ok so to make this "live" example work you have to follow a couple of steps.

Step 1:
When you go there type in "mar" (no quotes) and click the search button.
Step 2:
Once the search has found anyone with "mar" in their name it will display them with an "activate" button. Click on anyone doesn't matter to activate them.
Step 3:
You now need to select a product from the dropdown menu, I suggest for testing purposes choose "E Wizard". Then click on the "build invoice" button at the bottom of the form.
Step 4: Notice how the "productname" "E Wizard" is not displayed in the ( ITEM CODE DESCRIPTION ) column. It's only echo'ing the productdesc.

Try that see if you have a better understanding of what I'm talking about. I am echo'ing it correctly
Code:
<? echo "$productname"; ?>
but if you use firefox it tells you productname has no properties, that's why nothing is echo'ing. But I don't know why it doesn't have a property like the other items (price, productdesc).

I have another issue but that we can address after I hope if you or anyone can help me. :)
 
you are calling the function like so, from your onchange event:

Code:
showDescription(this, productdesc_1, price_1)

yet, you set up the function like this:

Code:
function showDescription(sel, productdesc, price, [red]productname[/red]){

at the very least, your function is expecting a fourth parameter.



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
My lord you are a saint. I have made a few errors in the code I provided you but your reply got me thinking and here is the proper working code:

Code:
function showDescription(sel, productdesc, price, productname){
    var opt = sel.options;
    if(opt[sel.selectedIndex].value == "productname"){
        productname.value = "product name";
		productdesc.value = "product description";
        price.value = "product price";
    }else{
		productname.value = opt[sel.selectedIndex].text;
		var ary = opt[sel.selectedIndex].value.split("|");
        productdesc.value = ary[0];
        price.value = ary[1];
	    }
    return true;
}

Thank you so much for jump starting my brain...I have been stuck on this for days now. :)
 
Uh oh...however I think I have come up with a snag, it's only working for the first set of products, if you try to add another product it won't do it. It's now saying productname_2 is not defined, would this be cause productname is not any array in the javascript?
 
Nevermind...such a doofus I am. I forgot that with the way the javascript is I needed to create a hiddenfield with the productname_# in order for it to echo correctly. I guess this is a bit of a hodge podge way of doing it but it's the only way I know. Thanks again for all your great help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top