如何在onchange事件中获取从javascript函数返回的值? [英] How do I grab the value returned from javascript function on onchange event?

查看:70
本文介绍了如何在onchange事件中获取从javascript函数返回的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试存储从Javascript函数返回的值,该函数在OnChange事件上调用。我在ASP Classic,HTML和Javascript中使用编码,但这很可能只是简单的HTML和Javascript。



这是我到目前为止编写的代码(我在将此代码粘贴到此框中时遇到了很多麻烦;我实际上是将SQL数据库表中的值输出到选择选项中,但我在这里简化了一些内容):



I am trying to store the value returned from a Javascript function, which is called on an OnChange event. I am using coding in ASP Classic, HTML, and Javascript, but this could very well be just straight HTML and Javascript.

Here is the code I have written thus far (I am having a LOT of trouble getting the code pasted in this box; I am actually outputting the values from a SQL database table into the select options, but I have simplified things here):

Dim ReturnValue: ReturnValue = ""

<select class="rounded" name="cboEventSites" id="cboEventSites" onChange="return DisplaySelection(this);">
<option value="Select One">Select One</option>
<option value="-9999" <%=IfSelected(iVenueID, "Not Listed-ADD NEW")%>>Not Listed-ADD NEW</option>

<%
sSQL = "SELECT EventSiteID, EventSiteName FROM CustomersToEventSites WHERE CustomerID = '" & iCustomerID & "' "

Set rsEventSites = oConn.Execute(sSQL)
																									
	Do While Not rsEventSites.EOF 
																										
		SiteID = Trim(rsEventSites("EventSiteID"))
		VenueName = Trim(rsEventSites("EventSiteName"))
																										
%>
<option value="<%=SiteID%>" <%=IfSelected(iVenueID, SiteID)%>><%=VenueName%></option>
<%

	reEventSites.MoveNext																		
	Loop
																									
	rsEventSites.Close
	Set rsEventSites =  Nothing																				rsEventSites.Close
%>																				%>
</select>

script type="text/javascript">
function DisplaySelection(selectObj) {
						
var selectedData = selectObj.value;
var idx = selectObj.selectedIndex;
	
// For testing:
window.document.write(selectedData);
return selectedData
				
};





我尝试过:



请参阅上面的代码。我无法在此区域粘贴任何代码。这个编辑器非常难以使用。



What I have tried:

See the code above. I could not paste any code in this area. This editor is extremely difficult to use.

推荐答案

您好,



您可以使用以下任一选项在你的onChange方法里面 -



1.使用document.getElementById('id-select-box')。value

2.如果你'然后使用Jquery然后使用Jquery选择器 - (#id-select-box).value)



如果您有任何问题,请告诉我。



谢谢。
Hi,

You can use either of following options inside your onChange method -

1. Use document.getElementById('id-select-box').value
2. If you're using Jquery then use Jquery selector - (#id-select-box).value)

Let me know if you've any questions.

Thanks.


这篇关于如何在onchange事件中获取从javascript函数返回的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆