Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting a variable equal to the value of a textbox on an ASP page

Posted on 2013-01-11
7
Medium Priority
?
1,381 Views
Last Modified: 2013-01-16
I am needing to set a variable = to a textboxes value.

for instance i want:

Var1 = txtbox1.value but when I do that I get:

Microsoft VBScript runtime error '800a01a8'

Object required: ''

/energysystc/electricalppmChlorAlkali.asp, line 1573

and if I do:

 Var1 = txtbox1
the response.write returns nothing.

I am just looking for the proper sytax or method on doing this.
0
Comment
Question by:jlcannon
[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
  • 3
  • 3
7 Comments
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 38766920
Will you please give some example code.

Do you want the the variable after the form is submitted?

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
var1=""
if request("textbox1")<>"" then
	var1=request("textbox1")
end if
%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
</head>
<h1>Var1 = 
<%
if var1<>"" then
	response.write var1
	else
	response.write "N/A. Please submit the form."
end if
%>
</h1>
<body>
<form name="form1" method="post" action="">
  <label for="textbox1"></label>
  <input type="text" name="textbox1" id="textbox1">
  <input name="Submit" type="submit" value="Submit">
</form>
</body>
</html>

Open in new window

0
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 38767094
If you want to get the value of the the text box before the form is submitted you need to use javascript and lets say you will put that to a hidden field and a div.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
var1=""
if request("textbox1")<>"" then
	var1=request("textbox1")
	hiddenfield=request("hidden1")
end if
%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Untitled Document</title>
<script>
var1=    document.getElementById("textbox1").value;
document.getElementById("hidden1").value=var1;
document.getElementById("hiddenvalue").innerHTML=var1;
</script>
</head>
<h1>Var1 = 
<%
if var1<>"" then
	response.write var1
	response.write ". The vaule of the hidden field is "&hiddenfield
	else
	response.write "N/A. Please submit the form."
end if
%>
</h1>
<body>
<form name="form1" method="post" action="">
  <label for="textbox1"></label>
  <input type="text" name="textbox1" id="textbox1" value="hello">
  <input type="hidden" name="hidden1" id="hidden1">
  
  <input name="Submit" type="submit" value="Submit">
</form>
<h2>Just the value in a div</h2>
  <div id="hiddenvalue"></div>
</body>
</html>

Open in new window

0
 

Author Comment

by:jlcannon
ID: 38767115
When I do the above it returns "N/A. Please submit the form" but there is clearly a number i the textbox so not sure why its not grabbing the number.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 38767291
I am used to doing this in jquery and it probably just needs a function.  What is it exactly you are trying to do.  "I am needing to set a variable = to a textboxes value."  Can you please give some sample code.

Are you trying to get a vbscript variable a value without submitting a form?  If so, what is the variable going to be used for?
0
 

Author Comment

by:jlcannon
ID: 38767384
<td width="80%" class="tablesmall">
<input type="text" size="5" name="PPMNumber" id="PPMNumber" value=<%=rs.fields("Off-Line Inspection Period") %>>
<input type="hidden" size="5" name="OLInspect1" value=<%=rs.fields("Off-Line Inspection Period") %>>

<%
 
   
    PPMNum3 = OLInspect1
    response.write PPMNum3
0
 
LVL 18

Expert Comment

by:nap0leon
ID: 38774723
The input does not exist during server side execution.

If you are looping through rs.fields to set the values in your table and want to be able to use those values later on during your server-side script but do not want to keep the record set open, you should assign those items to a variable that can be referenced later.

(While you are writing out each row):
<% OffLineInspectionPeriod_1 = rs.fields("Off-Line Inspection Period") %>
<td width="80%" class="tablesmall">
<input type="text" size="5" name="PPMNumber" id="PPMNumber" value=<%=OffLineInspectionPeriod_1%>>
<input type="hidden" size="5" name="OLInspect1" value=<%=OffLineInspectionPeriod_1 %>>

...

<br/>OffLineInspectionPeriod_1 is still valid later: <b><% Reponse.Write OffLineInspectionPeriod_1 %></b>

Open in new window




Or... use JavaScript to get the values that you placed into those specific fields:
<form name="goober">
<td width="80%" class="tablesmall">
<input type="text" size="5" name="PPMNumber" id="PPMNumber" value=3>
<input type="hidden" size="5" name="OLInspect1" value=3>
</td>
</form>
The value of the hidden input named "OLInspect1" is: 
<script>
oForm = document.forms.goober;
document.write(oForm.elements["OLInspect1"].value);
</script>

Open in new window

0
 

Author Closing Comment

by:jlcannon
ID: 38782547
works great, thank you
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

730 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