Solved

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

Posted on 2013-01-11
7
1,259 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 500 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
Industry Leaders: 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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