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

Problem updating fields based on drop down selection

Status
Not open for further replies.

jwalz

Programmer
Oct 31, 2000
78
US
I am trying to update some text fields in a form based on the selection of a drop down. I have figured out how to use asp scripting to access the database to look up the associated fields, but am having trouble figuring out how to grab the value from the drop down field and then use it when I look up the other data in my table. All of this needs to operate within a single page. Here is the code that I am using:

<script Language=&quot;VBScript&quot;>
function UpdtData()

//This is where I am trying to grab the selected value,
//which works, but I can't pass it into the next section
//of asp script.
t_id = document.JobFrame.Job.value
<%
jobs.MoveFirst
t_found = False
do while (Not(jobs.EOF) and Not(t_found))
'Value for t_id is null here
if (jobs.Fields(4) = t_id) then
t_client = jobs.Fields(3)
t_status = jobs.Fields(2)
t_title = jobs.Fields(5)
t_found = True
end if
jobs.MoveNext
Loop
%>
document.JobFrame.ClientName.value = &quot;<%=t_client%>&quot;
document.JobFrame.Status.value = &quot;<%=t_status%>&quot;
document.JobFrame.Title.value = &quot;<%=t_title%>&quot;
document.JobFrame.submit
end function
</script>
Please let me know what I am missing!
Thanks,
Janet
 
Could it be that you are overlooking the fact that the ASP script runs on the server. It builds an HTML page that may include <script>'s. It gives that page to the web server and it's job is finished. The web server sends the page along to someone's browser on their home computer. The browser renders the HTML as a web page and performs any commands in the <script>.

What this means is that the stuff in <% %> is not in the web page when the browser gets the page. You can View Source to confirm this.

Furthermore the <script> is not executed on the server, which is lucky because things like document.JobFrame don't exist on the server, they only exist in the browser.

Well, then there is the fact that only IE can execute a <script> written in VBScript, possibly a minor consideration these days since most of us use IE.

So what to do?

You might think about a different process for providing the information. Such as submitting the form with the t_id value, submit it to the ASP script, run the query, build the page with the resulting client, status, and title.

Both pages can look the same, they can be generated by the same script using logic to determine whether the page is being generated with or without a value for t_id in the form data.

Code:
<html>
...
<form name=&quot;Job&quot; action=&quot;job_selector.asp&quot;>
<select name=&quot;t_id&quot;>
  <option value=1>Programmer
   ...
</select>
...
</form>

<%
If Not IsNull ( Request.Form(&quot;t_id&quot;) ) Then
'Here would be the code to query the database
' using the value of t_id to select the jobs to be listed.
...
%>

<table>

<%
   jobs.MoveFirst
   t_found = False
   do while (Not(jobs.EOF) and Not(t_found))

      if ( jobs.Fields(4) = Request.Form(&quot;t_id&quot;) ) then
         t_found = True
%>

<tr>
  <td><%= jobs.Fields(3) %></td>
  <td><%= jobs.Fields(2) %></td>
  <td><%= jobs.Fields(5) %></td>
</tr>

<%
      end if
      jobs.MoveNext
   Loop
%>

</table>

<%
End If
%>

...
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top