User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 425,936 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,595 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 3815 | Replies: 5
Reply
Join Date: Mar 2007
Location: India
Posts: 28
Reputation: bhuvan83 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bhuvan83's Avatar
bhuvan83 bhuvan83 is offline Offline
Light Poster

Question linking dynamically added drop down using javascript

  #1  
Mar 8th, 2007
hi every1
i m using jsp in jbuilder9 to create a website
i have 2 drop down button
a1 and b1
when i select a option in a1 the values of b1 comes
if i change the value of a1 then the value of b1 also changes.
then i have a button to dynamically add 2 similar drop downs
i click the button.
the drop down are added
a2 and b2
but the problem is
when i select some thing in a2 the value of b1 changes instead of b2.
i m not getting the solution.
plz if any 1 can help me out.
thanks in advance
regards
Bhuvan
Last edited by bhuvan83 : Mar 8th, 2007 at 7:12 am.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: linking dynamically added drop down using javascript

  #2  
Mar 8th, 2007
you quite obviously have an error in your javascript...
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Mar 2007
Location: India
Posts: 28
Reputation: bhuvan83 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bhuvan83's Avatar
bhuvan83 bhuvan83 is offline Offline
Light Poster

Re: linking dynamically added drop down using javascript

  #3  
Mar 8th, 2007
but do u know the soln?
Reply With Quote  
Join Date: Oct 2006
Location: Sofia, Bulgaria
Posts: 135
Reputation: Rhyan is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Junior Poster

Re: linking dynamically added drop down using javascript

  #4  
Mar 9th, 2007
Originally Posted by bhuvan83 View Post
but do u know the soln?


It looks like your buttons A2 and B2 copy exactly the code you used to create a1 and b1. Use an iteration to change id and names of the dynamically added buttons, so that your b button become b2, not b1.

it should look something like this
var iteration = lastButtonNameNumber + 1;
var new_a_ButtonName = 'a' + iteration;
var new_b_ButtonName = 'b' + iteration;

And then access the new b-button value using something like
document.form.new_b_ButtonName.value = ....

Hope you can figure it out by yourself.

Good luck.
" Of all the things I've lost,
I miss my mind the most...."
Mark Twain
Reply With Quote  
Join Date: Mar 2007
Location: India
Posts: 28
Reputation: bhuvan83 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bhuvan83's Avatar
bhuvan83 bhuvan83 is offline Offline
Light Poster

Re: linking dynamically added drop down using javascript

  #5  
Mar 9th, 2007
dear rhyan
i m doing this
i m getting the name a2 and b2.
can u send me a small example where u r adding the drop down dynamically n when the 1st one is clicked the values of 2nd 1 comes.
Reply With Quote  
Join Date: Mar 2007
Location: India
Posts: 28
Reputation: bhuvan83 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
bhuvan83's Avatar
bhuvan83 bhuvan83 is offline Offline
Light Poster

Re: linking dynamically added drop down using javascript

  #6  
Mar 12th, 2007
c if there r any error in th code n reply.<br>
this is the code i m using to create the drop boxes dynamically.<br>

var i=0;
var option=new Array();
function insRow(){
var d=document.getElementById("div");
d.innerHTML+="<select id='D"+i+"' class='input' onChange='getSh(this.selectedIndex)'><option>Select Here</option>"+
<%
rs=st.executeQuery("select * from productTab");
while(rs.next())
{
%>
"<option><%=rs.getString("productName")%></option>"+
<%}%>
"</select>"
d.innerHTML+="<select name='DD"+i+"' id='DD"+i+"' class='input'><option>Select Here</option></select>"
d.innerHTML+="<select name='DDD+i' id='DDD+i' class='input'><option>Select Here</option></select>"
d.innerHTML+="<input type=text name='T+i' id='T+i' class='input-time'><br>"

option +=["DD"+i];
option +=["D"+i];
i++;
}

function getSh(selectedcitygroup)
{
document.getElementById("DD+i").options.length=1
if(selectedcitygroup>0){
for(i=0;i<cities[selectedcitygroup].length; i++)
document.getElementById("DD+i").options[document.getElementById("DD+i").options.length]=new Option(cities[selectedcitygroup][i].split("|")[0], cities[selectedcitygroup][i].split("|")[1])
}
}
Last edited by bhuvan83 : Mar 12th, 2007 at 4:57 am.
Bhuvan Aggarwal
There is no word impossible.
its i m possible
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 9:20 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC