Solved

Cassic ASP call vbScript on_click of button

Posted on 2011-03-18
15
379 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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
 
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 143

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 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