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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do i call a field of a form on the current page, within ASP code? 1

Status
Not open for further replies.

debrac

IS-IT--Management
Jan 9, 2001
48
0
0
AU
how do i call a field of a form on the current page, within ASP code?
eg.
<% sqlstring = &quot;SELECT DISTINCT interest FROM main WHERE (interest Is Not Null AND type = &quot; & [field on form] & &quot;) ORDER BY main.interest;&quot;

thanks.
 
I've done a something similiar by setting the SQL text to a DTC recordset by a value passed by a form. But I am really not sure about the code for your sqlstring because I am really new to sql. I do know however that you can get the value of a field on a form on a previous page by doing the following.

formfieldvar = Request(&quot;frmfield&quot;)

'frmfield being the field on the form on the previous page

On the previous page containing the form you would need to do:

thisform.action = &quot;Second.asp&quot;
thisform.submit

I hope this helps you at least a little.

tammym
 
Give the field an ID (use ID attribute) then you can refer to it any where on the page - IDNAME.text.
 
thanks both of you. helpful.
but still having trouble accessing value of select box.

 
Do you mean a list box? Can you give a little more info about your situation?

tbmishue
 
i want to resubmit a page, and calculate a value of a second list box - filled with data from database, based on the value selected in the first list box.
thanks

 
Sounds like your are trying do so something similiar to what I have here?

Sub CatRecordset_onbeforeopen()

cHoldcat = Request(&quot;Catlstbx&quot;)

'Catlstbx is the listbox on ASP1.asp

strSQL= &quot;SELECT Subject AS Subject, StartDate AS [Start Date], StartTime AS [Start Time] FROM infotable WHERE (Category = '&quot; & cHoldcat & &quot;')

CatRecordset.setSQLText (strSQL)

End Sub

Hope this helps a bit s-)

tbmishue
 
yes, the same, except i need to get the value of the list box on current page (same page).
 

I haven't every used this method, but I did get it from the Help with Visual Studio. Maybe you can use it.

Listbox DTC help.

getValue Method


Returns a value from an object.

Syntax

object.getValue([nIndex | strField])

Parameters

object

A script object.

nIndex

Index of an item in the zero-based list. If left null, the index defaults to the currently selected item. The index of the currently selected item is equivalent to the value of the selectedIndex property.

strField

A string of the field name.

Remarks

For Listbox and OptionGroup objects, the method returns a text string that corresponds to the HTML attribute VALUE.

For the fields object, the method returns the value of the field for the current record.

Note For the OptionGroup object and ASP pages, there is an another way to return the value setting. You can reference an OptionGroup object by using its name with &quot;_value&quot; appended to it. For example, you could pass the value from an OptionGroup whose id is &quot;myOptionGroup&quot; by calling:

myVar = request(&quot;myOptionGroup_value&quot;)

In the scripting object model, you could return the same result with:

myVar = myOptionGroup.getValue()


More Help


Listbox Design-Time Control


Creates a Listbox script object, which creates an intrinsic HTML list box that can be bound to data.

Remarks

You can set the properties of the Listbox control at design time using the Properties window and the Listbox Properties dialog box.

Set the ControlStyle property to create a standard list box or a drop-down list box.

You can bind the Listbox control to one recordset and populate the list from another recordset by doing a lookup on the Lookup tab of the Listbox Properties dialog box.

If you want to create a static list instead of one that is data-bound, select the Static list option on the Lookup tab.

Note The scripting platform specifies where an object's script is run - either on the client (Microsoft® Internet Explorer 4.0 DHTML) or on the server (ASP). Thus, the scripting platform determines whether the object is available under Client Objects & Events or Server Objects & Events in the Script Outline window.

For the Listbox control, the Scripting Platform property is specified on the General tab of the Listbox Properties dialog box. For more information, see theDTCScriptingPlatform property. For detailed information about choosing a scripting platform, see Writing Script for Script Objects.

Scripting Notes

Call the hide, show, and isVisible methods to control how the list box is displayed.

To change the items of the Listbox object, call the addItem, removeItem, clear, and getCount methods.

To manipulate the current item, call the getValue, setValue, getText, and setText methods.

Call the selectByValue or selectByText methods to select an item in the list.

For more information about the run-time object, see Listbox Script Object. For information on scripting and objects, see Scripting with Design-Time Controls and Script Objects.


tbmishue
 
on the form where the list box is (<select>) -- just set the action to the same page -- that way, the form will submit to itself --

Then, you put an onChange event for the <select> of

<select name=theSelect onChange=&quot;document.formName.submit();&quot;>

So that when a user makes a choice, the form submits itself, the page reloads, you retrieve the value as people have suggested above, and populate your second <select> based on that value.

:)
Paul Prewett
penny.gif
penny.gif
 
ok. thanks. i have got that far.
the problem now is that i dont know how to call the value of the list box (which has been selected) on the same page.
 
Yeah, this is a hassle in JavaScript too.

Assuming your using a SELECT input when you say list box you can access it in JavaScript using the following:

wantedvalue=formname.selectname.optionname.value

Of course the OPTION VALUE must be the same as the actual value in the options list. Eg, <OPTION VALUE=&quot;fish&quot;>Fish

Now this works in JavaScript but I don't know about ASP. But I'm hoping it helps you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top