Page 1 of 1

Product Templates - Adding an "onChange" field

Posted: Tue May 20, 2008 1:20 pm
by ryankivi1
I'd like to be able to add a javascript call to some product templates. I see it already adds in the "id" field for accessing it with javascript.


Have this:
<select name="ctl00$wpm$ShowProduct$ctl07$InputField_23" id="ctl00_wpm_ShowProduct_ctl07_InputField_23">
Would like this:
<select name="ctl00$wpm$ShowProduct$ctl07$InputField_23" id="ctl00_wpm_ShowProduct_ctl07_InputField_23" onChange="DoSomething()">

Would this be done in one of the databases? I've been looking around and am a bit confused.

Thanks for any help.

Regards,

Re: Product Templates - Adding an "onChange" field

Posted: Tue May 20, 2008 2:38 pm
by jmestep
What display page are you working on?

Re: Product Templates - Adding an "onChange" field

Posted: Tue May 20, 2008 3:33 pm
by ryankivi1
Judy,

Thank you for the post. Don't understand your question.

Regards,

Re: Product Templates - Adding an "onChange" field

Posted: Tue May 20, 2008 6:35 pm
by jmestep
Is this a display page for a product and if so, which. I just ran across something the other day that explained how you can put javascript on a asp control so it might help you if I can find the reference and you can tell me where you are trying to put it.

Re: Product Templates - Adding an "onChange" field

Posted: Tue May 20, 2008 6:36 pm
by ryankivi1
Yes its a product page for display/ordering.

Re: Product Templates - Adding an "onChange" field

Posted: Tue May 20, 2008 6:37 pm
by jmestep
OK, now I'll try to find the code I read.

Re: Product Templates - Adding an "onChange" field

Posted: Wed May 21, 2008 8:59 am
by jmestep
The code I was thinking of was for adding an onchange attribute to an html input tag in the code behind for a page.
I think what you want needs to be done in the App_Code/producthelper.cs. There is code there that handles an automatic post back for kit options and I think you can adapt it for the template fields code in the section above. Kit option code:

Code: Select all

public static List<int> BuildKitOptions(Product product, PlaceHolder phOptions)
    {
        List<int> selectedChoices = new List<int>();
        foreach (ProductKitComponent pkc in product.ProductKitComponents)
        {
            KitComponent component = pkc.KitComponent;
            if (component.InputType != KitInputType.IncludedHidden && component.KitProducts.Count > 0)
            {
                // CREATE A LABEL FOR THE ATTRIBUTE
                phOptions.Controls.Add(new LiteralControl("<tr><th class=\"rowHeader\">" + component.Name + ":</th>"));
                // ADD THE CONTROL TO THE PLACEHOLDER
                phOptions.Controls.Add(new LiteralControl("<td align=\"left\">"));
                WebControl o = component.GetControl();
                if (o != null)
                {
                    Type oType = o.GetType();
                    if (oType.Equals(typeof(RadioButtonList)))
                    {
                        ((RadioButtonList)o).AutoPostBack = true;
                    }
                    else if (oType.Equals(typeof(DropDownList)))
                    {
                        ((DropDownList)o).AutoPostBack = true;
                    }
                    else if (oType.Equals(typeof(CheckBoxList)))
                    {
                        ((CheckBoxList)o).AutoPostBack = true;
                    }
                    phOptions.Controls.Add(o);
                    // SEE WHETHER A VALID VALUE FOR THIS FIELD IS PRESENT IN FORM POST
                    List<int> theseOptions = component.GetControlValue(o);
                    selectedChoices.AddRange(theseOptions);
                }
                phOptions.Controls.Add(new LiteralControl("</td></tr>"));
            }
        }
        return selectedChoices;
    }