Solved

OnChange Event for DropDown List

Posted on 2004-09-27
4
1,167 Views
Last Modified: 2008-03-17
I am having a problem... I have an access database and an ASP application. On my add screen I am populating a dropdown box with a field from the database. I want to use the OnChange event to fill in a textbox below with the corresponding information. I am combining HTML, ASP, and VBScript for my Onchange event.

I believe the easiest way to achieve this is to create an array.  I receive two JS Errors when I run this page
the first error is expected end (this occurs at the end of this line: var pubArray = new Array()

Then I get this error object undefined.  (this occurs at this line: <option></option>)

Below is my code!  Can somebody please help?  I have lost hours on this and I would really appreciate any input.
--------------------------------------------------------------------------------


objRS.Open "tblJournalNames", objDC, 0, 1

If Not objRS.EOF Then
objRS.MoveFirst
%>

<script type="text/vbscript" language="vbscript">
var pubArray = new Array()

function applytoLabel(a)
document.Form1.txtJournal.value = a.value
document.Form1.txtAuthor.Value = pubArray(a.SelectedIndex)
end function
</script>
<select name="comboJournal" onChange="applytoLabel(this)">
<option></option>
<%
x = 0
Do While Not objRS.EOF
%>
<script language="vbscript">
pubArray<%= x %> = "<%= objRs.Fields("Pub_Code").Value %>"
</script>
<option value="<%= objRS.Fields("Journal_Name") %>"><%= objRS.Fields("Journal_Name") %></option>
<%
objRS.MoveNext
Loop
%>
</select>
<font face="Tahoma">
<% end if %>
0
Comment
Question by:JCWright30
[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
4 Comments
 

Expert Comment

by:grantrj
ID: 12195575
Hi,
I may be missing the point but instead of <option></option> could you have <option value=-1></option>?
This should hopefully ensure that the object is defined as I beleive that an option object is defined if it has a value....

Hope this helps
0
 

Author Comment

by:JCWright30
ID: 12196413
Here is the fix.  This works well and I wanted to post if for others having similar problems.

objRS.Open "tblJournalNames", objDC, 0, 1

If Not objRS.EOF Then
objRS.MoveFirst
%>

<script type="text/vbscript" language="vbscript">
dim pubArray()

function applytoLabel(a)
if a.SelectedIndex = 0 then
document.Form1.txtJournal.value = ""
document.Form1.txtAuthor.Value = ""
else
document.Form1.txtJournal.value = a.value
document.Form1.txtAuthor.Value = pubArray(a.SelectedIndex - 1)
end if
end function</script>
<select name="comboJournal" onChange="applytoLabel(this)">
<option></option>
<%
x = 0
Do While Not objRS.EOF
%>
<script language="vbscript">
ReDim Preserve pubArray(<%= x %>)
pubArray(<%= x %>) = "<%= objRs.Fields("Pub_Code").Value %>"
</script>
<option value="<%= objRS.Fields("Journal_Name") %>"><%= objRS.Fields("Journal_Name") %></option>
<%
x = x + 1
objRS.MoveNext
Loop
%>
</select>
<font face="Tahoma">
<% end if %>
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12554197
PAQed with points refunded (250)

modulo
Community Support Moderator
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

734 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