473,734 Members | 2,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript refresh a select box without refreshing page

178 New Member
Hi, I am trying to improve the usabilty of an app I have written and it would be great if I could refresh the content of my select boxes without refreshing the whole page.

I am sure this could be done. perhaps using iFrames. Can anyone shed some light?
Nov 21 '08 #1
9 24146
RamananKalirajan
608 Contributor
Refreshing the Select Box withut refreshing the page means in what way you want to refresh the select box. Wether are u adding the Database values into that select box or user defined values in that page should be added to the select box.

Regards
Ramanan Kalirajan
Nov 21 '08 #2
cleary1981
178 New Member
the select box is populated from my database. when I add a new item to my database i want to see the values in the select box without refreshing.
Nov 21 '08 #3
gits
5,390 Recognized Expert Moderator Expert
so you want to push an update to a webapp when your database changes without user interaction? you just need to use an ajax-call and poll the db with it ... you have to decide how often you need that and you may use setInterval() for this purpose ... you just cannot really push things to the client ... the client has to request the update ...

kind regards
Nov 21 '08 #4
cleary1981
178 New Member
Yeah i have the function of adding to my database on the same page so when I add a new item to my database I want the selectbox which is a list of records to now contain the new one. Can you show me how this is done with ajax?
Nov 21 '08 #5
gits
5,390 Recognized Expert Moderator Expert
that is not nessecary then ... you could add the option to the DB with the call and besides that you just need to add it to the node with dom-methods to avoid requests/traffic ... what have you done so far?
Nov 21 '08 #6
cleary1981
178 New Member
Its is neccessary because I have three select boxes linked together. I need to turn my requests into ajax requests. Thanks for your help anyway. Below are the unctions I am currently using to populate my select boxes

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. require "config.php"; // database connection details 
  4. echo "
  5.  
  6. function fillType(){
  7.     //this function is used to fill the companies in main.php on load
  8. ";    
  9.  
  10. $q11=mysql_query("SELECT type FROM module_type");
  11. echo mysql_error();
  12. while($nt11=mysql_fetch_array($q11)){
  13. echo "addOption(document.form1.newtype, '$nt11[type]', '$nt11[type]');";}// end of while
  14. ?>
  15. }
  16.  
  17. function fillType2() {
  18.  
  19. removeAllOptions(document.form1.selecttype);
  20. addOption(document.form1.selecttype, "", "Select", "");
  21. <?php    
  22. $q77=mysql_query("SELECT type FROM module_type");
  23. echo mysql_error();
  24. while($nt77=mysql_fetch_array($q77)){
  25. echo "addOption(document.form1.selecttype, '$nt77[type]', '$nt77[type]');";}// end of while
  26. ?>
  27. }
  28.  
  29. function fillNewSub() {
  30.     removeAllOptions(document.form1.newsub);
  31.     addOption(document.form1.newsub, "", "Select", "");
  32.  
  33.     <?php
  34.         $q22=mysql_query("select distinct(type) from subtype"); 
  35.         while($nt22=mysql_fetch_array($q22)){
  36.             echo "if(document.form1.newtype.value == '$nt22[type]'){";
  37.             $q32=mysql_query("select subtype from subtype where type='$nt22[type]' order by subtype asc");
  38.             while($nt32=mysql_fetch_array($q32)){
  39.             echo "addOption(document.form1.newsub,'$nt32[subtype]', '$nt32[subtype]');";
  40.  
  41.             } // end of while loop
  42.             echo "}"; // end of JS if condition
  43.         }
  44. ?>
  45. }
  46.  
  47. function fillselectsub(){
  48.     removeAllOptions(document.form1.selectsub);
  49.     addOption(document.form1.selectsub, "", "Select", "");
  50.  
  51.     <?php
  52.         $q55=mysql_query("select distinct(type) from subtype"); 
  53.         while($nt55=mysql_fetch_array($q55)){
  54.             echo "if(document.form1.selecttype.value == '$nt55[type]'){";
  55.             $q56=mysql_query("select subtype from subtype where type='$nt55[type]' order by subtype asc");
  56.             while($nt56=mysql_fetch_array($q56)){
  57.             echo "addOption(document.form1.selectsub,'$nt56[subtype]', '$nt56[subtype]');";
  58.  
  59.             } // end of while loop
  60.             echo "}"; // end of JS if condition
  61.         }
  62. ?>
  63. }
  64.  
  65. function fillselectmod(){
  66.     removeAllOptions(document.form1.selectmod);
  67.     addOption(document.form1.selectmod, "", "Select", "");
  68.  
  69.     <?php
  70.         $q44=mysql_query("select distinct(subtype) from module"); 
  71.         while($nt44=mysql_fetch_array($q44)){
  72.             echo "if(document.form1.selectsub.value == '$nt44[subtype]'){";
  73.             $q45=mysql_query("select module_name from module where subtype='$nt44[subtype]' order by module_name asc");
  74.             while($nt45=mysql_fetch_array($q45)){
  75.             echo "addOption(document.form1.selectmod,'$nt45[module_name]', '$nt45[module_name]');";
  76.  
  77.             } // end of while loop
  78.             echo "}"; // end of JS if condition
  79.         }
  80. ?>
  81. }
  82.  
  83.  
  84. function removeAllOptions(selectbox)
  85. {
  86.     var i;
  87.     for(i=selectbox.options.length-1;i>=0;i--)
  88.     {
  89.         //selectbox.options.remove(i);
  90.         selectbox.remove(i);
  91.     }
  92. }
  93.  
  94. function addOption(selectbox, value, text )
  95. {
  96.     var optn = document.createElement("OPTION");
  97.     optn.text = text;
  98.     optn.value = value;
  99.  
  100.     selectbox.options.add(optn);
  101. }
  102.  
Nov 21 '08 #7
gits
5,390 Recognized Expert Moderator Expert
so you mean you have to update all three select-nodes when adding a new option to one of them? as i said ... then you need something that does the following steps:

1. user adds an option
2. start your ajax-call and insert the option to the db
3. when inserted retrieve the data from the db
4. send back the result
5. the onreadystatecha nge-handler could now update the list-nodes
Nov 21 '08 #8
cleary1981
178 New Member
ok heres what I have for the first select. I can get the values into my program but how do I put the values into the select?

Expand|Select|Wrap|Line Numbers
  1. function ajax_filltype(){
  2.     var x=0;
  3.     var url = "filltype.php?x=" + escape(x);
  4.     url = url + "&dummy=" + new Date().getTime();
  5.     request.open("GET", url, true);
  6.     request.onreadystatechange = populateselecttype;
  7.     request.send(null); 
  8. }
  9. function populateselecttype() {
  10.     if (request.readyState == 4) {
  11.         var response = request.responseText;
  12.         var splitResult = response.split("%%");
  13.         for (i=0; i<splitResult.length-1; i++){
  14.             alert(splitResult[i]);
  15.             //add each option i to select box
  16.         }
  17.     }
  18.  
  19. }
php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. require "config.php";
  4.  
  5. $q1=mysql_query("SELECT type FROM module_type");
  6. while($r = mysql_fetch_array($q1)){
  7.         echo $r['type'] . '%%';
  8.  
  9.   }
  10. ?>
Nov 21 '08 #9
cleary1981
178 New Member
never mind it was just

Expand|Select|Wrap|Line Numbers
  1. function populateselecttype() {
  2.     if (request.readyState == 4) {
  3.         var response = request.responseText;
  4.         var splitResult = response.split("%%");
  5.         for (i=0; i<splitResult.length-1; i++){
  6.             document.form1.selecttype.options[document.form1.selecttype.length] = new Option(splitResult[i], splitResult[i]);
  7.         }
  8.     }
  9.  
  10. }
Nov 21 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
4455
by: Steve | last post by:
Hi, I have a private website for 20 people that is similar to a web email client like hotmail. There are two frames, one on the left with links for "New", "History", "Todays" and a frame on the right with a table for viewing the contents of these messages. The left pane checks back with the server every few seconds to see if any new messages need to be processed and updates count accordingly.
3
23542
by: Troy | last post by:
Hello- I have a website that uses a custom built webserver to serve the pages. (Please don't ask me why my boss had his own web server written). I am displaying a log of information that is an unknown number of rows. This is currently displayed in a table. The table is generated by some code that we had to write (thank you custom webserver) so that the webserver will parse HTML files and fill in the tags we created with some data...
9
1907
by: paul | last post by:
Hi All, We have a small dilemma. We have the following page: http://giggsey.com/m00Cow.php (don't ask about the content) that we want to turn into an interactive application for some new intake students at our school. However - we want to have multiple client PCs running a web interface that will allow them to type in their name / a message, and then this message appears on the "scroller" page, which will be on a projector.
7
2821
by: Assimalyst | last post by:
Hi, I want to create a popup to notify a user that the server side process has completed successfully. I intended to use a javascript alert to do this, although ideally the icon should be different, but thats another story . . . Anyway, on successful completion of the process i use this piece of code:
10
3475
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario ------------- I have perl script which simply runs a ps on a Solaris server and generates a static html page with all of the code perfectly and this html page works fine when viewing it statically or with a META REFRESH header tag. The idea is to give the user...
2
2018
by: Jimbo1 | last post by:
Hi there, I'm new to this group, so first of all I'd like to say a big "Hello"! Moving on, I'm a database developer who has found himself in a grey zone between the database and the web front end. I'm making some enhancements to an Oracle database that's using a (now obsolete and unsupported) utility called "WebDB" to provide a related web application.
4
5358
by: Peter | last post by:
ASP.NET I have an application which use ASP.NET Autocomplete extender which works great. But I have a question how to update all the fields on the screen using Ajax. Users starts typing in a text field which causes the Autocomplete extender to display 10 like items, after the users selects an item (which is a key in the database) I want the application to go to the database retrieve a record and populate the fields.
23
1775
by: WebFoot | last post by:
Is there a reliable way for a webpage to either break out or refuse to display when a hostile website puts it in a frame? I know about the JavaScript solution, but not all visitors have JavaScript enabled. I also know about the target="_top" solution, but that only works if the visitor clicks on a link.
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.