Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Jul 2008
Posts: 11
Reputation: zappan is an unknown quantity at this point 
Solved Threads: 0
zappan zappan is offline Offline
Newbie Poster

DOM select HTML

 
0
  #1
Aug 6th, 2008
Hi everyone,

I've an issue here. i want load the data from database and i want it appear at DOM select. what i had done,first i load data to hidden text and use a javascript load to DOM select. But the problem is i need to click on select textbox first before the data is appear and also other problem i can't select other option.here is my code.

PHP code.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <head><script type='text/javascript' src='script.js'></script></head>
  2. <body>
  3. <tr>
  4. <td>
  5. <input type='hidden' id='hiddenState' value='$custState' size='28'></td></tr>
  6.  
  7. <tr>
  8. <td>
  9. <select id='state' onClick='return retrieveOption();'>
  10. <option value='apple'>Apple</option>
  11. <option value='banana'>Banana</option>
  12. <option value='car'>car</option>
  13. <option value='mouse'>mouse</option>
  14. </td>
  15. </tr>
  16. </body>
/#############################################

javascript code.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function retrieveOption(){
  2. var var_State=document.getElementById("hiddenState").value;
  3. var var_Option=document.getElementById("state");
  4.  
  5. for(var i=0;i<var_Option.length;i++){
  6. if (var_Option[i].value==var_State)
  7. {
  8. var var_Text=var_Option[i].text;
  9. var_Option[i].selected=true;
  10.  
  11. }
  12. }
  13. }
thank you.
Last edited by digital-ether; Aug 6th, 2008 at 7:20 am. Reason: Please wrap your code in [code] ... [/code] tags
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 11
Reputation: zappan is an unknown quantity at this point 
Solved Threads: 0
zappan zappan is offline Offline
Newbie Poster

Re: DOM select HTML

 
0
  #2
Aug 6th, 2008
Please someone help me....
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: DOM select HTML

 
0
  #3
Aug 6th, 2008
Let me get this straight, you want to update the values of your <select><options> using values you retrieve from a database -- based on what option your user selects from that <select> field initially? Is that correct?

If so, you might expand upon this code snippet to change the values of your select menu.
If you have the same number of new options as the original then it's easy, if you need to add or remove options depending on the results you get back you can also do that with DOM methods, or you can construct an entire new <select> input element with the new options and swap out the old with the new using either DOM methods or innerHTML method.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function retrieveOption () {
  2. var state = document.getElementById('state');
  3. for ( var i = 0; i < state.length; i ++ ) {
  4. if ( state[i].selected ) {
  5. // grab the new values here
  6. // example of updating one <option> value
  7. state[i].value = 'pizza';
  8. state[i].firstChild.nodeValue = 'Pizza';
  9. }
  10. }
  11. }

Please clarify your problem some more if you need more help.

Thanks
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC