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 374,006 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 2,837 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: 697 | Replies: 1
Reply
Join Date: Dec 2007
Posts: 1
Reputation: xaviergxf is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
xaviergxf xaviergxf is offline Offline
Newbie Poster

Complex Select generation with DOM

  #1  
Dec 26th, 2007
Hi,

I have a table in my database that´s like that:
create table t(
id int,
name varchar(30),
father_id int,
Primary Key(id),
Foreign Key(father_id) references t(id)
);

I´m trying to do the follow:

1) Create a select box witch each option has an id, that when selected it search on the db table t for the father_id.
2)If this search returns anything it will create with dom(create element) a new select.
3)This select created also will search in the db table t for father_id.

Did anyone knows, how can i do that?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 442
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 65
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Complex Select generation with DOM

  #2  
Dec 27th, 2007
Well the javascript would be something along the lines of
  1. var newElement = document.createElement('option');
  2. newElement.text = <name variable here>;
  3. newElement.id = <id variable here>;
  4. newElement.value = <whatever else here>;
  5. var targetSelect = getElementById('whatever the select id is');
  6. try{targetSelect.add(newElement,null);}catch(ex){targetSelect.add(newElement);}
That creates a new element then adds it as a child element to the select box. The try/catch is there because IE doesn't conform to standards.
Last edited by ShawnCplus : Dec 27th, 2007 at 11:56 am.
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Reply

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

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

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