简体   繁体   中英

Java script values set into index of asp drop down

I have asp.net drop down list but I want to load previous classic asp page value into index of the drop down list using Java script.

I can able to take the previous page value with use of Java script.but I am unable set into asp drop down index when page is loaded. Drop down list showing only data from data base not from Java script value.

Protected void page_load()
{
    this.BindCountrydropdown();
}
Protected void BindCountrydropdown()
{
     /*I have written stored procedure to load values using Data adapter and data table*/
     this.ddlCountry.DataTextField=“Countryname”;
     this.ddlCountry.DataValueField=“CoubtryID”;
     this.ddlCountry.Databind();
}

In .aspx page. Java script:

<script>
    function loadpreviouspagevalues()
    {
        document.getElementById(“ddlCountry”).value=window.opener.parent.document.getElementById(“CountryName”).value;
    }
</script>
<body onload =“ loadpreviouspagevalues()”>
    <asp:DropDownList ID=“ddlCountry” runat =“server”> </asp:DropDownList>
   ...

Country name should loaded into ddlCountry index values.

First of all, there are multiple errors just in your javascript function.

function loadpreviouspagevalues(){
    document // should not be a capital "D"
    .getElementById //  No Extra "." should go after this
    ("ddlCountry").value = window.opener.parent.document.getElementById("CountryName").value; 
    // I am also skeptical about the inverted commas that you have used here. These are not surely correct
}

Change these and test. Also, when dealing with JavaScript, it is crucial to check browser console to see if any error is there and resolve it accordingly.


I see, you are fetching the value from another page, I would suggest you first validate if the value is properly being returned or not. If it is, then there is the syntactical issue that you need to fix in JavaScript.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM