HTML, JavaScript And CSS Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingHTML, JavaScript And CSS Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old June 10th, 2008, 06:55 AM
edmondj edmondj is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 72 edmondj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 26 m 25 sec
Reputation Power: 5
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

Reply With Quote
  #2  
Old June 10th, 2008, 08:19 AM
new learner new learner is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2008
Location: India
Posts: 70 new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 5 h 10 m 27 sec
Reputation Power: 104
Smile

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.

Reply With Quote
  #3  
Old June 10th, 2008, 09:43 AM
edmondj edmondj is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 72 edmondj User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 26 m 25 sec
Reputation Power: 5
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

Reply With Quote
  #4  
Old June 10th, 2008, 11:19 AM
geog272 geog272 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 geog272 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 29 m 23 sec
Reputation Power: 2
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();'>

Reply With Quote
  #5  
Old June 13th, 2008, 04:56 AM
new learner new learner is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2008
Location: India
Posts: 70 new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 5 h 10 m 27 sec
Reputation Power: 104
Smile

Quote:
Originally Posted by edmondj
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


Hi,

Was wondering whether u tested it out.
In case u have, i had a query about the same.

Reply With Quote
  #6  
Old June 24th, 2008, 09:54 AM
pinkferret pinkferret is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 14 pinkferret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by geog272
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();'>


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?

Reply With Quote
  #7  
Old June 24th, 2008, 10:36 AM
geog272 geog272 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 geog272 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 29 m 23 sec
Reputation Power: 2
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.

Reply With Quote
  #8  
Old June 24th, 2008, 11:15 AM
pinkferret pinkferret is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 14 pinkferret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by geog272
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.


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

Reply With Quote
  #9  
Old June 24th, 2008, 11:54 AM
geog272 geog272 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 geog272 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 29 m 23 sec
Reputation Power: 2
Can you make have a default value for the first dropdown of "None Selected" or "Please make a selection" ?

Reply With Quote
  #10  
Old June 24th, 2008, 01:09 PM
pinkferret pinkferret is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 14 pinkferret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by geog272
Can you make have a default value for the first dropdown of "None Selected" or "Please make a selection" ?

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?

Reply With Quote
  #11  
Old June 24th, 2008, 03:31 PM
geog272 geog272 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 geog272 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 29 m 23 sec
Reputation Power: 2
Can you post your code?

Reply With Quote
  #12  
Old June 24th, 2008, 04:08 PM
pinkferret pinkferret is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 14 pinkferret User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 35 sec
Reputation Power: 0
Quote:
Originally Posted by geog272
Can you post your code?


<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>

Reply With Quote
  #13  
Old June 25th, 2008, 02:57 AM
new learner new learner is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2008
Location: India
Posts: 70 new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 5 h 10 m 27 sec
Reputation Power: 104
Question

Quote:
Originally Posted by geog272
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.



Hi,

Is it possible to have other stuff before the city and country selections.

Reply With Quote
  #14  
Old June 25th, 2008, 02:23 PM
geog272 geog272 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2007
Posts: 35 geog272 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 29 m 23 sec
Reputation Power: 2
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.

Reply With Quote
  #15  
Old June 26th, 2008, 12:23 AM
new learner new learner is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: May 2008
Location: India
Posts: 70 new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level)new learner User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 5 h 10 m 27 sec
Reputation Power: 104
Quote:
Originally Posted by geog272

And, you could have stuff in front of the country selections. Just keep passing things through the forms using the hidden input type.


Hi,

Thanks, will try out & get back.

Reply With Quote