Link to home
Start Free TrialLog in
Avatar of aco000636
aco000636Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Cassic ASP call vbScript on_click of button

Hi All
Any help gratefully received.

Very little ASP experience and m trying to make minor change to existing ASP page but cant work out how to get the value of a text box and pass it to a vbScript.

I have a page with a dropdown, a user should select a vaue, press a button, a vaule of a text box needs to be passed to a vbScript.

See following code

<html>
<head>
<title>ACO Test</title>

<script language="VBSript">
<!--
Sub Button_OnClick
Dim frmPeriod
Set frmPeriod = document.forms["Period"]
	MsgBox "Value is " & frmPeriod.text3.value
	response.write "the value is: " & frmPeriod.text3.value
	Response.Write Request.Querystring("text3")

End Sub
-->
</script>
<script type="text/Javascript">

function GetValue(ax){
//alert(ax);
var mysel =document.forms['Period'].elements['PeriodDD'];
var seltxt = mysel.options[mysel.selectedIndex].text; 

document.forms["Period"].text1.value=ax;
document.forms["Period"].text3.value=seltxt;

}

</script>
<style>
@import url(integration.css);
</style>

<form name="Period">
<select name="PeriodDD" id="PeriodDD" onchange='GetValue(document.forms["Period"].PeriodDD.value)';>
<Option value=1> Jan 2011</Option>
<Option value=2 selected>Feb 2011</Option>

</select>

<%Response.Write Request.Querystring("document.forms(0).text3.value")%>


<br /><br />
<p>Result is: <input type="text" id="text1" name="text1"></p>
<p>Value is: <input type="text" id="text3" name="text3"></p>
<p>New button: <input type="button" id="btn1" Value="Button"</p>
</form>
</head>
</body>
</html>

Open in new window

Avatar of lucky20
lucky20
Flag of United States of America image

If you select an item from from drop down list box ,the values are passing to remaing textboxes..
I posted the same question previously..
this is the result i got..


I am just posting my code here to check,it may help you

to get the values into text box from selection ,you need to use ajax.

<body>
<% 
OpenSQLConn 
Dim itemid, sql, item, unit 
itemid = Request("itemid") 
If Trim(itemid) <> "" Then 
'these two lines are for debugging only 
'Response.Write "{""item"":""testing"",""unit"":""testing"",""status"":""OK"",""error"":""""}"   
'Response.End 
 
 
      sql = "SELECT * FROM items WHERE Itemid=" & itemid 
      Set res=Conn.Execute(sql) 
      If NOT res.EOF then 
            item=res("Item") 
            unit=res("unit") 
            Response.Write "{""item"":""" & item & """,""unit"":""" & unit & """,""status"":""OK"",""error"":""""}" 
			
		     
      Else 
            Response.Write "{""item"":"""",""unit"":"""",""status"":""!OK"",""error"":""No Results found!""}" 
      End If 
      Response.End 
End If  
%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
 
<html> 
<head> 
<title>sample2</title> 
 
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> 
<script type="text/javascript"> 
$(function(){ 
      $("#itemid").bind('change',function(){ 
            $.get('<%= Request.ServerVariables("SCRIPT_NAME")%>?itemid='+$('#itemid').val(), function(result){ 
                                var data=$.parseJSON( result.replace(/(^[^\[{]+|[^\]}]+$)/g,'') ); 
                                if(!data) 
                                { 
                                        $('#error').html('Invalid server response. Expected JSON string. Got '+result.replace(/[>]/g,'&gt;').replace(/[<]/g,'&lt;')+' instead.'); 
                                } 
                else if( data.status=='OK') 
                { 
                                        $('#item').val(data.item); 
                                        $('#unit').val(data.unit); 
                                } 
                                else 
                                { 
                                        $('#error').html(data.error); 
                                } 
                        }); 
      }); 
}); 
</script> 
</head> 
<body> 
 
<form method="post" action="sample2.asp"> 
<div id="error"></div> 
<table> 
<tr><td>Item</td> 
<% 
SQL = "Select * from items order By Itemid" 
Set rs = Conn.Execute(SQL)%> 
<td> <select name="itemid" id="itemid"> 
<option value="">Please Choose</option> 
 <% Do While Not rs.EOF %> 
<option value='<%=rs("Itemid")%>'><%=rs("Itemid")%>, <%=rs("Item")%></option> 
<% 
rs.MoveNext 
Loop 
  
%> 
</select></td></tr> 
 
<tr><td>Item </td>    
   <td><input type="text" name="item" id="item" value=""></td></tr> 
<tr><td>Unit</td> 
 <td><input type="text" name="unit" id="unit" value=""></td></tr> 
  
</table> 
</form> 
</body> 
</html>

Open in new window


please find the ajax code line from 32 to 54
plz check this out..
it works..

I hope this will solve ur problem..

<html>  
<head>  
<title>ACO Test</title>  
  

<script type="text/Javascript">  
  
function getvalue(){  
   var combo = document.getElementById("period"); 
   var itembox = document.getElementById("text1"); 
   var ibox = document.getElementById("text3"); 
    itembox.value = combo.options[combo.selectedIndex].text 
	ibox.value = combo.options[combo.selectedIndex].text 
} 
</script> 


<style>  
@import url(integration.css);  
</style>  
  
<form name="form1">  
<select name="PeriodDD" id="period">  
<Option value=1> Jan 2011</Option>  
<Option value=2 selected>Feb 2011</Option>  
  
</select>  
<input type="button" id="btn1" Value="Button" onclick="getvalue()">

  
<p>Result is: <input type="text" id="text1" name="text1"></p>  
<p>Value is: <input type="text" id="text3" name="text3"></p>  
</form>  
</head>  
</body>  
</html>

Open in new window

change the line number 13  from

ibox.value = combo.options[combo.selectedIndex].text  

to

ibox.value = combo.options[combo.selectedIndex].value

you will get the list box value..
Avatar of aco000636

ASKER

Lucky20 - Appreciate appreciate your comment/help.

I dont have an issue running the code to get the values back from the select. Its passing the values to a vbScript when I click the button. Not sure if you have IIS on your machine but if you paste my code in to a asp page you'll see what I mean.

As you can see I tried various methods without sucess. Mainly because I dont really understand how to catch input.
Thanks
Lucky20 - apologies missed the last post. looking at your comment now :-)
I copied ur code in asp page and made chages to it..
yes i have iis on my machine..
Hi there
I can see that your code does fill the combo. However, unfortunately I'm still lost.
I want a user to open the page
select a value in the combo
press a button that will pass the currently selected item to my vbScript

sort of
as you saw the orginal code did fill the text boxs. Now I had the values, I wanted to pass them on to another script [vbScript]
<input type="button" id="btn1" Value="Button1" onclick="Run_vbScript_Function(combo.value)">

Appreciate you taliking time to contribute.
after selecting combo,the values are passing to textboxes.. these text box values you want to send it to vbscript right?correct me if I am wrong..
Hi, yes thats correct.
The text boxes will be used for returning a message to the user, processing report for period...
and the numeric value used to pass to a stored proc which fills the rest of the page with a report.

So on click, read vaules of text boxes, pass values to vbScript, write a comment for confirmation, call stored proc, fill the page.

regards ACO
I will try to do this now... let see any one can help you mean while..
ASKER CERTIFIED SOLUTION
Avatar of lucky20
lucky20
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi there
thanks for your code, that seems to have worked. FF is a problem but I can get round that. Really appreciate your help with this.
Regards ACO
Hi All
In the end I put the problem out to tender and paid someone to fix it for me. However, the results were pretty simple in the end, running the SQL was placed within the <form> section and everything works fine.

Thanks for everyones input.
Regards ACO

</head>
<body>
<form action="salesreport.asp" method="post">
<%="Logged in as: " & tUser %>



<%

if not bAuth THen
%>
	NOT AUTHORISED
<%
Else

	Dim i, iCurMonth, strPeriod
	Dim receivedMonth



	if Request.Form("Period") = "" then
		receivedMonth = Month(Date)
	else
		receivedMonth = CInt(Request.Form("Period"))
	end if

	iCurMonth = Month(Date)

	'the following on click, I would like it to refresh the query
	%>
	<%= "!" & receivedMonth & "!" %>
	<input type="submit" value="  -  Run  -  "/>
	<select name="Period" id="Period">
	<%
	If CInt(iCurMonth) > 1 Then
		For i = CInt(iCurMonth) + 1 To 12
	%>
	<Option value="<%=i%>" <% if receivedMonth=i then Response.write("selected") end if %>><%=MonthName(i) & " - " & CStr(Year(Date) - 1)%></Option>
	<%

		Next
		For i = 1 To CInt(iCurMonth)
	%>
	<Option value="<%=i%>" <% if receivedMonth=i then Response.write("selected") end if %>><%=MonthName(i) & " - " & CStr(Year(Date))%></Option>
	<%

		Next
	Else
		For i = 1 to 11
	%>
	<Option value="<%=i%>" <% if receivedMonth=i then Response.write("selected") end if %>><%=MonthName(i) & " - " & CStr(Year(Date))%></Option>
	<%
		Next
	%>
	<Option value="<%=i%>" <% if receivedMonth=i then Response.write("selected") end if %>><%=MonthName(i) & " - " & CStr(Year(Date))%></Option>
	<%
	End If




	Dim cn, rc, strConn
	'ACO UPDATE
	strConn = "myConnection;"

	Set cn = CreateObject("ADODB.Connection")
	Set rc = CreateObject("ADODB.Recordset")

	'recordset.Open Source, ActiveConnection, CursorType, LockType, Options
	'---- CursorType Values ---- 
	Const adOpenForwardOnly = 0 
	Const adOpenKeyset = 1 
	Const adOpenDynamic = 2 
	Const adOpenStatic = 3 
	'---- LockTypeEnum Values ---- 
	Const adLockReadOnly = 1 
	Const adLockPessimistic = 2 
	Const adLockOptimistic = 3 
	Const adLockBatchOptimistic = 4 
	'---- CursorLocationEnum Values ---- 
	Const adUseServer = 2 
	Const adUseClient = 3 


	dim sqlCustomReport, sqlCountCalls, sqlEngNotActiveToday

		'---if bAuth then
		sqlCustomReport = "EXECUTE PROCEDURE spSalesAnalysis_v2(" & CStr(receivedMonth) & ");"
					
%>
	<table>
		<thead>
			<th>Title</th>
			<th>Month</th>
			<th>Value</th>
			<th>Currency</th>
		</thead>
	<%

		cn.Open strConn
		rc.CursorLocation = adUseClient
		rc.CursorType = adOpenStatic
		rc.LockType = adLockReadOnly

	'ON button click, run this report

		Set rc = cn.Execute( sqlCustomReport )


		IF rc.EOF = True Then
			response.write "<tr><td colspan='4'>No data returned...</td></tr>"
		Else
			rc.MoveFirst
			do while not rc.EOF
		%>
			<tr>
				<td><%=trim(rc.Fields(0))%></td>
				<td><%=trim(rc.Fields(1))%></td>
				<td style="text-align:right;"><%=FormatNumber(trim(rc.Fields(2)), 2, -1, 0, -1) %></td>
				<td style="text-align:center;"><%=trim(rc.Fields(3))%></td>
			</tr>
		<%
				rc.MoveNext
			Loop
		If rc.State <> 0 Then rc.close
		If cn.State <> 0 Then cn.Close

		end if
end if
%>
</form>

Open in new window

Avatar of Guy Hengel [angelIII / a3]
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.