简体   繁体   中英

variable path in href tag

<a id="m1" class="audio {autoPlay:false, addGradientOverlay:true}"
href="MusicFolder/" + document.getElementById("DropDownList1").value +  "/" +
document.getElementById("DropDownList2").value>document.getElementById("DropDownList2").value</a>

I got above code in my aspx web page but its not working. I am trying to get variable file path by combining two dropdowns selected values. Please can anybody help that what I am doing wrong and how can I correct above code.

Drowpdown asp.net code is below

        <asp:DropDownList runat="server" id="DropDownList1" AutoPostBack="True" DataSourceID="AccessDataSource6" DataTextField="TranslationLang" DataValueField="TranslationLang" Height="25px" Width="100%"></asp:DropDownList>
        <asp:AccessDataSource ID="AccessDataSource6" runat="server" DataFile="Database/HFx.mdb" SelectCommand="SELECT [TranslationLang] FROM [Translation]">
        </asp:AccessDataSource>
        <br />
        <asp:DropDownList runat="server" id="DropDownList2" AutoPostBack="True" DataSourceID="AccessDataSource7" DataTextField="Surah" DataValueField="Surah" Height="25px" Width="100%"></asp:DropDownList>
        <asp:AccessDataSource ID="AccessDataSource7" runat="server" DataFile="Database/HFx.mdb" SelectCommand="SELECT [Surah] FROM [TranslationSurah] WHERE ([Lang] = ?) ORDER BY [No]">
        <SelectParameters>
        <asp:controlparameter ControlID="DropDownList1" Name="Lang" PropertyName="SelectedValue" Type="String" />
        </SelectParameters>
        </asp:AccessDataSource>

Browser executes the JS inside an href only when it is clicked but for that you need to mention "javascript:" at the beginning of content inside href. The following code should work

<a id="m1" class="audio {autoPlay:false, addGradientOverlay:true}"
href="javascript:window.location='MusicFolder/' + document.getElementById('DropDownList1').value +  '/' + document.getElementById('DropDownList2').value">document.getElementById('DropDownList2').value</a>

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