JavaScript查找选定下拉项目的索引,传递到超链接
JavaScript to Find Index of Selected Dropdown Item, Pass to Hyperlink
我遇到了一些麻烦,经过相当多的研究,一直无法找到解决方案。我在SharePoint Designer 2010工作,有一个ASP.net下拉列表填充。我想从下拉列表中获得所选项目的索引值(例如1),并将其传递给用于调出EditForm的URL。aspx页面。见下文,感谢您提供的任何帮助!
<script type="text/javascript">
function redirect(url) {
var ddl = document.getElementById('DropDownList1');
alert("HI!");
var index = ddl.selectedIndex;
var value = ddl.options[index].value;
location.href = url + value;
return false;
}
</script>
<asp:LinkButton runat="server" id="LinkButton1"
href="https://chartiscorp.sp.ex3.secureserver.net/Lists/System_Information/EditForm.aspx?id="
onclientclick="javascript:redirect(this.href)">Edit System Info</asp:LinkButton>
<asp:DropDownList runat="server" id="DropDownList1" DataValueField="Title"
DataTextField="Title" DataSourceID="spdatasource1" />
您应该使用呈现的ID:
var ddl = document.getElementById('<%=DropDownList1.ClientID%>');
和LinkButton
的OnClientClick
事件:
<asp:LinkButton onclientclick="...">
使用
获取索引var index = ddl.selectedIndex;
或者如果你想获得值,使用
var value = ddl.options[ddl.selectedIndex].value;
我建议在函数中进行重定向,而不是在HTML属性中。集合:
<script type="text/javascript">
function redirect(url) {
var ddl = document.getElementById('<%=DropDownList1.ClientID%>'),
index = ddl.selectedIndex,
value = ddl.options[index].value;
location.href = url + value;
return false;
}
</script>
<asp:LinkButton runat="server" id="LinkButton1"
href="../Lists/System_Information/EditForm.aspx?id="
onclientclick="redirect(this.href)">LinkText</asp:LinkButton>
<asp:DropDownList runat="server" id="DropDownList1" DataValueField="Title"
DataTextField="Title" DataSourceID="spdatasource1" />
相关文章:
- 制作一个不带HTML a标记但在动画播放完毕后指向其他页面的超链接
- 单击超链接时,如何使用Google Maps API v3缩放地图
- 用超链接替换URLS
- 使用JavaScript从超链接加载时的默认下拉值
- Hammer.js阻止在Android Webview中点击超链接
- 将超链接添加到“;标题“;标记文本
- 文本建议的超链接
- 用Javascript按钮替换Javascript超链接
- 删除默认的ui超链接行为
- 谷歌将广告超链接映射到国家标记
- 如何在点击超链接时调用fullcalendar回调
- 单击“禁用其他超链接”
- 为Angularjs制作超链接
- 指向的超链接刚刚赢得'不起作用
- 如何将超链接添加到通过传单创建的传单多段线.Draw
- 如何禁用鼠标中键单击超链接以在新选项卡或新窗口中打开
- 如何在每个动态创建的ImageButton周围包装超链接?Visual Studio
- 将数据库中的超链接添加到查询结果
- 在javascript中向索引数组添加超链接
- JavaScript查找选定下拉项目的索引,传递到超链接