Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pass variable to html textbox

Status
Not open for further replies.

holidayIT

IS-IT--Management
Apr 2, 2004
138
US
How can i pass a variable to a textbox or hidden field (prefer hidden field) in an html page???? i have vbscript code that opens a popup and takes an input to a variable. i need the variable to be then set to a hidden field in the html page. can anyone help me???
 
Why do you need it to be part of the html on the page? Why not just use the variable itself?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
i am using a third party form processor to store it in sql and mail it out. therfore, i need the variable to be stored as either a textbox or hidden field (i prefer hidden so the user cannot change it). i originally had the page setup to store it in sql and mail it all by itself. i got it working, but not on all machines. there a several settings and active x is not installed on all machines. i am already using the form processor for other things, and it really easy, except in this case. so i just need to store the varialbe in a hidden field.

i am already using the on_load event to get the variable.
 
AFAIK all you would need to do is to created the hidden field when you design the page then set its value attribute to equal the variable.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
all that does is set it equal to the variable name not the variable data. unless i don't know what you mean, whch is more probable. how do i do that???

i have tried to say <input type ="hidden" name="whatever" value = inputVar> i have even tried inputVar in qoutes.
 
In the script, try saying whatever.value = inputVar

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
it gives an error and tells me object required "whatever
 
Sorry, add this to the tag for the hidden field id="whatever"

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
This code works for me. See if you can tweak it to get what youwant:
Code:
?<HTML>
<HEAD>
<TITLE></TITLE>
<META NAME="GENERATOR" Content="Microsoft Visual Studio">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=UTF-8">
<script id=clientEventHandlersVBS language=vbscript>
<!--

Sub Button1_onclick
	strInput = InputBox("Enter value")
	Text1.Value = strInput
End Sub

-->
</script>
</HEAD>
<BODY>

<!-- Insert HTML here -->
 <input id=Button1 type=button value=Button>
 <input 
id=Text1 type=text>

</BODY>
</HTML>

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
it need to happen on window_onload event


and it doesn't work still says object required.


now you may be feel the pain that i do.
 
I don't think you will hav any objects in the window_onload event. Thus I can't think of any way that you would change the value of a text field that doesn't exist yet. I'll play around and see what I can come up with.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
ahhh.....

i see. in that case, is there anyway that i can call to actions with one button??? the action for submit calls the asp form processor, but if i could also get it to call a sub and then set the hidden field in the sub and/or then call the asp from the sub too.
 
I was wrong. THis worked for me:
Code:
?<HTML>
<HEAD>
<TITLE></TITLE>
<META NAME="GENERATOR" Content="Microsoft Visual Studio">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=UTF-8">
<script id=clientEventHandlersVBS language=vbscript>
<!--


Sub window_onload
	strInput = InputBox("Enter value")
	Text1.Value = strInput
End Sub

-->
</script>
</HEAD>
<BODY>

<!-- Insert HTML here -->&nbsp;
 <input 
id=Text1 type=text>

</BODY>
</HTML>

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
that's exactly how i have mine setup. but it's weird that for me it always gives me the object required.

the thing is that i need the submit button to go to a form action with a method="post"

if i could also get the button to go to a sub, i think it'd work. is there a way to get the sub to do the form action with "post"???
 
Can you post an example of exactly what you have?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I commented out the authentication (as that is what the input box is for) And the SQL works fine. I commented that out too.


<HTML>
<HEAD>
<TITLE>BLAH</TITLE>
<Script Language="VBScript" Runat="server">

Dim inputWO
Dim strAccess
Dim myConn
Dim myRecordset
Dim DB_Connect_String
Dim strSurveyMail, rstSurvey, strWorkOrder

DB_Connect_String ="driver={SQL Server};server=servername;database=name"

'Set myConn = CreateObject("ADODB.Connection")
'set myRecordset = CreateObject("ADODB.Recordset")

'Set the connection properties to point to work order database'
'myConn.Open = DB_Connect_String

'strSurveyMail = <select statement here>

'myRecordset.Open strSurveyMail, myConn

'Set rstSurvey = myRecordset

Sub window_onload

inputWO = Inputbox("Enter your Work Order Number")
'If not empty, then continue'
'If Not (rstSurvey.Eof and rstSurvey.Bof) Then
'While Not rstSurvey.Eof ' *Loop through all work orders that need surveys'

'strWorkOrder = rstSurvey("Work_order_number")
'If CLng(inputWO) = CLng(strWorkOrder) Then
'strAccess = <update statement>
'myConn.Execute strAccess
msgbox "Thank you. Please continue."
WorkOrderNumber.Value = inputWO
'MyConn.close
Exit Sub
'End If
'rstSurvey.MoveNext
'Wend
'MsgBox "Sorry. That work order number has either already been surveyed, or has not been selected for a survey." , vbOKOnly, "Incorrect Work Order Number"
'location.href="IT Survey.htm" 'error page if not correct'
'Else
' location.href="IT Survey.htm"
'End If
'MyConn.Close
End Sub

</Script>

<form action=" method="post">

<META content="Microsoft FrontPage 5.0" name="GENERATOR">
<META content="FrontPage.Editor.Document" name="ProgId">
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>
<BODY>
<input type="hidden" name="WorkOrderNumber" id="WorkOrderNumber" >
 
BTW - in my own defense, I DID NOT use Front Page. I inherited this web page from someone else. i am using dreamweaver and visual basic .net

I may not be the sharpest pencil in the box with this stuff, but i am not the dullest either.
 
Hello holidayIT,

You do not run window_onload server-side. Clearly separate codes server- & client-sides.

regards - tsuji
 
So i should run it client side? it's server side since the database and page are on the same server, and therefore i will not take-up bandwidth transfering data across the network. In any case it doesn't fix my problem.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top