This is a migrated thread and some comments may be shown as answers.
Javascript not seeing dropdown value
2 Answers 8 Views
This is a migrated thread and some comments may be shown as answers.
Web Services
Top achievements
Rank 2
Web Services asked on 20 Aug 2013, 08:23 PM
I have a panel and dropdown like so
<telerik:RadAjaxPanel runat="server" ID="panel" LoadingPanelID="loadingPanel">
<asp:DropDownList ID="itemDrop" runat="server"></asp:DropDownList>
    </telerik:RadAjaxPanel>
    <telerik:RadAjaxLoadingPanel ID="loadingPanel" BackgroundPosition="Center" runat="server">
        <img id="Img1" alt="Loading..." src="~/images/loading.gif" runat="server" style="border: 0px;" />
    </telerik:RadAjaxLoadingPanel>

In the code behind I attach a JS function to the onchange event of the dropdown. Here is the JS function
function showFields(id) {
    var dd = document.getElementById(id);
    var itemArr = (dd.options[dd.selectedIndex].value).split(";;;");
     
    var perDiv = document.getElementById("percentDiv");
    var quantDiv = document.getElementById("quantityDiv");
     
    var disValue = itemArr[1];
    var item = itemArr[0];
     
    if (item == "-1") {
        perDiv.style.display = "none";
        quantDiv.style.display = "none";
    }
    else {
         
        //see if we show quantity as well
        if (disValue > 0) {
            perDiv.style.display = "block";
            quantDiv.style.display = "block";
        }
        else {
            perDiv.style.display = "none";
            quantDiv.style.display = "block";
        }//if disValue > 0
 
         
    }//if item == -1
}

Basically, I pass in the client id of the drop down. It then reads the value and decides whether or not to show some text boxes. They are set to display none by default. The problem I have is, when I do a post back with the ajax panel, the text boxes go back to being hidden. I am also calling this javascript function in the page load. When I remove the ajax panel, it sees the dd and keeps the text boxes visible. However, when I add the ajaxpanel back in, the textboxes go back to hidden on the postback. Any ideas why?






2 Answers, 1 is accepted

Sort by
0
Web Services
Top achievements
Rank 2
answered on 22 Aug 2013, 02:02 PM
Any help here, this is a little urgent.
0
Eyup
Telerik team
answered on 23 Aug 2013, 10:32 AM
Hi,

When calling a script function from the code behind and you have AJAX enabled on your page, there are some specifics:
http://demos.telerik.com/aspnet-ajax/ajax/examples/common/recreatescripts/defaultcs.aspx

Furthermore, you should wrap your script in RadScriptBlock:
http://www.telerik.com/help/aspnet-ajax/ajax-radscriptblock-radcodeblock.html

Hope this helps.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Ajax
Asked by
Web Services
Top achievements
Rank 2
Answers by
Web Services
Top achievements
Rank 2
Eyup
Telerik team
Share this question
or