Solved

Cassic ASP call vbScript on_click of button

Posted on 2011-03-18
15
370 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:aco000636
  • 7
  • 6
15 Comments
 
LVL 1

Expert Comment

by:lucky20
ID: 35166505
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
0
 
LVL 1

Expert Comment

by:lucky20
ID: 35166842
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

0
 
LVL 1

Expert Comment

by:lucky20
ID: 35166865
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..
0
 

Author Comment

by:aco000636
ID: 35166965
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
0
 

Author Comment

by:aco000636
ID: 35167031
Lucky20 - apologies missed the last post. looking at your comment now :-)
0
 
LVL 1

Expert Comment

by:lucky20
ID: 35167100
I copied ur code in asp page and made chages to it..
yes i have iis on my machine..
0
 

Author Comment

by:aco000636
ID: 35167144
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.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 1

Expert Comment

by:lucky20
ID: 35167271
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..
0
 

Author Comment

by:aco000636
ID: 35167340
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
0
 
LVL 1

Expert Comment

by:lucky20
ID: 35167377
I will try to do this now... let see any one can help you mean while..
0
 
LVL 1

Accepted Solution

by:
lucky20 earned 500 total points
ID: 35168047
try this

<html>  
<head>  
<title>ACO Test</title>  
  
<script language="VBScript"> 
<!--

Sub btnclick 
Dim frmPeriod  
 
        MsgBox "Value is " & Period.text3.value 
        response.write "the value is: " & Period.text3.value  
        Response.Write Request.form("text3")  
  
End Sub  
-->
</script>


<script type="text/Javascript">  
function GetValue(){  

 var combo = document.getElementById("PeriodDD");   
   var itembox = document.getElementById("text1");   
   var ibox = document.getElementById("text3");   
    itembox.value = combo.options[combo.selectedIndex].value  
        ibox.value = combo.options[combo.selectedIndex].text   

}  
  
</script>  
<style>  
@import url(integration.css);  
</style>  
  
<form id="Period"action="">  
<select name="PeriodDD" id="PeriodDD" onchange="GetValue()">  
<Option value=1> Jan 2011</Option>  
<Option value=2>Feb 2011</Option>  
  
</select>  
  
<%Response.Write Request.form("document.forms(0).text3.value")%>  
  
  

<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" onclick="btnclick()"></p>  
</form>  
</head>  
</body>  
</html>

Open in new window

0
 

Author Comment

by:aco000636
ID: 35171426
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
0
 

Author Comment

by:aco000636
ID: 35838300
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

0
 
LVL 142

Expert Comment

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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now