Forum Moderators: open

Message Too Old, No Replies

question on how to modify this script more

         

RogueDogg

9:57 am on Jul 1, 2006 (gmt 0)

10+ Year Member



Ok so here is the script I found:

// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
<!--
function showDescription(whatForm){
if(document.forms[whatForm].product.value=="none"){
document.forms[whatForm].productdesc.value="product description"
}else{
document.forms[whatForm].productdesc.value=document.forms[whatForm].product.value
}}
// -->
</script>

So basically this will allow someone to create a drop down menu and populate it however they wish, in my case a db query and when the "product" is selected it will display the "product description" where ever I chose, in my case a textarea. My question is how can I add to this? Meaning if I wanted to also display the price for the product selected along with the description, how can I include the price variabe in this? I will put the price in a textarea as well. Make sense? I've tried modifying the script using what has been given to me but I cannot seem to make it work right, any changes I make seem to mess the script up and then it doesn't work.

texmex

12:24 pm on Jul 2, 2006 (gmt 0)

10+ Year Member



Insufficient info for a complete answer, but on the face of it, I'd have thought, replace this:

document.forms[whatForm].productdesc.value=document.forms[whatForm].product.value

with

var msg=document.forms[whatForm].product.value +
"\n Now only " + price;
document.forms[whatForm].productdesc.value=msg;

(Note within the value of a textarea the \n means newline)

RogueDogg

4:27 am on Jul 3, 2006 (gmt 0)

10+ Year Member



hmmm let me check to see if this might work. I will get back to you. Thx for your suggestion.

EDIT:
Nope that did not work, when I select a product from the drop down list it does nothing, it no longer shows the description in the textarea and does not show the price in the text box either.

texmex

11:52 am on Jul 3, 2006 (gmt 0)

10+ Year Member



You really need to get a bit more diagnostic. "Nope that did not work" doesn't exactly give a definitive description of what is going wrong.

I suggest you download firefox and install the console2 extention. Then instead of a non descript don't work, you'll be able to see what the problem is.

RogueDogg

8:52 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



Ok according to the error console on firefox:

Price is not defined on line 24

Here is line 24:

"\n Now only " + price;

This is what I've been able to come up with and what is happening is when I chose a product from the drop down list it displays the productdescritpion in both the text area ( which is what I want ) and in the text box ( which should be the price ). Now that I'm able to get both areas populated with information now it's just a matter of getting the information in the script in the correct order? You think?

<SCRIPT LANGUAGE="JavaScript">
function showDescription(whatForm){
if(document.forms[whatForm].product.value=="ProductName"){
document.forms[whatForm].productdesc.value=="ProductDesc"
document.forms[whatForm].price.value=="Price"
}else{
var msg=document.forms[whatForm].price.value=document.forms[whatForm].product.value;
document.forms[whatForm].productdesc.value=msg;
}}
</script>

RogueDogg

10:01 pm on Jul 3, 2006 (gmt 0)

10+ Year Member



Ok I see why my last post is working like it is. In my form I have this for my drop down menu option:

echo "<option value = '".$record["ProductDesc"]."'>".$record["ProductName"]."\n";

That alone only allows me to display the ProductName ( drop down menu ) and ProductDescription ( text area or where I ever I want ). So what I need to do now is somehow get it to recognize all or atleast one more field ( Price ). Make any sense?

RogueDogg

3:02 am on Jul 5, 2006 (gmt 0)

10+ Year Member



Problem solved. With the help from another forum we were able to figure it out. If you would like me to post the code just ask and I will, so maybe others can learn from it as I have learned.

Thanks again for your help.