|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
JavaScript - Help with dropdown list
I have a drop down list reading from a table off a database. The table consists of 2 columns of data. Is there a way in javascript where i can do an onchange event on the drop down list (user selects value from dropdown) and get the value of the 2nd column based on the selection populated into a dropdown or a text box? Not sure how to do this but any insight would be great!
Thanks much edmond |
|
#2
|
|||
|
|||
|
Hi,
Just check this out in these forums itself ( forums.aspfree.com/code-bank-54/dynamic-triple-linked-dropdowns-99849.html by lafin boy ) . Perhaps could be useful to you. |
|
#3
|
|||
|
|||
|
thanks! i was thinking about dynamic linked drop down list but wasn't sure. will take a look at lafinboys triple dynamic linked drop down list. thanks again for the page
|
|
#4
|
|||
|
|||
|
The following site is a nice example as well, with the code available:
http://www.texaswebdevelopers.com/examples/our_supplier_test.asp I've used the above strategy with javascript to submit the form onchange... so when the user makes a change to the first dropdown menu, the form is submitted and the page is refreshed with values in the second drop down menu that are based on the user's selection in the first dropdown: Code:
<script language="JavaScript">
<!--
function doit()
{
document.catform.submit();
}
//-->
</script>
And then in the form... Code:
<form name='catform' method='post' action='blah.asp'> <select name='whichcategory' onchange='doit();'> |
|
#5
|
|||
|
|||
|
Quote:
Hi, Was wondering whether u tested it out. In case u have, i had a query about the same. |
|
#6
|
|||
|
|||
|
Quote:
is there any way i can modify this code in my form so that when a user is done selecting the country and city they are from, they continue filling data in the form and then are able to submit the form, and once submitted a different page is loaded? |
|
#7
|
|||
|
|||
|
sure. the action element of the form indicates where the page will be posted, if you want to post it to a new page, then you put that page's name in there.
you can have other stuff after the city and country selections -- just include them all in the single form. So, something like this would have the country and city dropdowns, then some inputs for the user to put in their first and last name.: Code:
<form name='form' method='post' action='blah.asp'>
<select name='country' onchange='doit();'>
<option value='usa'>USA</option>
...other country choices here....
<select name='city' onchage='doitagain();'>
<%
'**CHOOSE YOUR CITY BASED ON THE COUNTRY CHOICE**
SQL = "SELECT CityName FROM tbl_locations WHERE Country LIKE '" & Request.Form("country") & "'"
Set RS=MyConn.Execute(SQL)
While NOT RS.EOF
Response.Write "<option value='" & RS("cityName") & "'>" & RS("cityName") & "</option>"
RS.MoveNext
Wend
%>
<input type='text' name='firstname'>
<input type='text' name='lastname'>
<input type='submit' value='GO'>
</form>
Then on the following page you can retrieve the values using Request.Form("firstname") or Request.Form("country") etc. |
|
#8
|
|||
|
|||
|
Quote:
when the page first loads the first dropdown list is already populated by a vbscript, hence it already displays the first value in it, and if i have to make that value my selection the onchange event is ignored |
|
#9
|
|||
|
|||
|
Can you make have a default value for the first dropdown of "None Selected" or "Please make a selection" ?
|
|
#10
|
|||
|
|||
|
Quote:
yeah i just did that and it works, BUT, this section where i have to do this thing is located in a tabular form, and its the last tab on the form. after selecting the country, the page refreshes, and loads the first tab, how do i make it load the last one? |
|
#11
|
|||
|
|||
|
Can you post your code?
|
|
#12
|
|||
|
|||
|
Quote:
<head> ..... <script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script> <script src="SpryAssets/SpryCollapsiblePanel.js" type="text/javascript"></script> <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" /> <link href="SpryAssets/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" /> .... <script type="text/javascript"> <!-- function RefreshType() { document.MyForm.submit(); } //--> </script> </head> Zbody> <div id="Info" class="TabbedPanels"> <ul class="TabbedPanelsTabGroup"> <li class="TabbedPanelsTab" tabindex="0">Customer Info</li> <li class="TabbedPanelsTab" tabindex="0">Car Info</li> <li class="TabbedPanelsTab" tabindex="0">Sale Info</li> <li class="TabbedPanelsTab" tabindex="0">TradeIn Info</li> <li class="TabbedPanelsTab" tabindex="0">Loan</li> </ul> <div class="TabbedPanelsContentGroup"> ...... <div class="TabbedPanelsContent"> <form method="post" id="LoansData" name="MyForm" action="Thispage.asp"> Finanziaria:<select id="Loan" name="Loan" onchange="RefreshType()"> <% if StLoan = "" then response.write("<option>Make A Choice</option>") do until RsLoan.eof response.write("<option value=" & RsLoan.fields("Loan")) if RsLoan.fields("Loan") = StLoan then response.write(" selected") end if response.write(">") response.write(RsLoan.fields("Loan")) response.write("</option>") RsLoan.MoveNext loop RsLoan.Close set RsLoan=Nothing %> </select> </form> </div> </div> </div> |
|
#13
|
|||
|
|||
|
Quote:
Hi, Is it possible to have other stuff before the city and country selections. |
|
#14
|
|||
|
|||
|
Okay, I'm not so sure about the tabbed thing (maybe someone else here has more experience with that), but I think what I would try to do is something like this:
Code:
<form name='formOne' method='post' action='ThisPage.asp'>
...form stuff in here, choose a country...
</form>
<form name='formTwo' method='post' action='ThisPage.asp'>
...form stuff in here, this is where you select the city...
<input name='country' value='<% Request.Form("country") %>'type='hidden'>
</form>
<form name='formThree method='post' action='Nextpage.asp'>
...form stuff in here, other things you want the user to fill in...
<input name='country' value='<% Request.Form("country") %>' type='hidden'>
<input name='city' value='<% Request.Form("city") %>' type='hidden'>
<input type='submit' value='GO'>
</form>
And, you could have stuff in front of the country selections. Just keep passing things through the forms using the hidden input type. |
|
#15
|
|||
|
|||
|
Quote:
Hi, Thanks, will try out & get back. |