mjsulliv Posted February 18, 2010 Share Posted February 18, 2010 I want to be able to pass non-displayed data on a html page and use JavaScript to algorithmically load select-options with values from this data. The data source is a database table. My thought was to have php build a hidden table from which the JavaScript could pull the information. Fundamentally, is that the best solution or is there a better way. Assuming it is I can’t seem to code the correct syntax for using the table attribute hidden.Any help / thoughts would be appreciated. Link to comment Share on other sites More sharing options...
ShadowMage Posted February 18, 2010 Share Posted February 18, 2010 There is no table attribute 'hidden' (is there?). You can always use style='visibility: hidden;' though. Link to comment Share on other sites More sharing options...
mjsulliv Posted February 18, 2010 Author Share Posted February 18, 2010 There is no table attribute 'hidden' (is there?). You can always use style='visibility: hidden;' though.According to:http://www.w3schools.com/html5/html5_ref_s...dattributes.aspthere is.?. Link to comment Share on other sites More sharing options...
Synook Posted February 18, 2010 Share Posted February 18, 2010 Maybe you want to look into AJAX, so the JavaScript script can query your database asynchronously of page loadings? Link to comment Share on other sites More sharing options...
ShadowMage Posted February 18, 2010 Share Posted February 18, 2010 According to:http://www.w3schools.com/html5/html5_ref_s...dattributes.aspthere is.?.Ah. HTML 5. Gotcha.Just out of curiosity, though, why is this part of HTML standards? Isn't this a presentational attribute? I thought presentational stuff was supposed to kept in CSS, not mixed in with HTML? I would also consider the <mark> tag to be presentational. Link to comment Share on other sites More sharing options...
Ingolme Posted February 18, 2010 Share Posted February 18, 2010 According to:http://www.w3schools.com/html5/html5_ref_s...dattributes.aspthere is.?.That's HTML 5, which isn't very well supported. I would advise against making pages with HTML 5 for at least one more year if not longer because for now there's no proper consistency between modern browsers. Besides, there are better alternatives using PHP or Javascript.If you use pure PHP you can simply choose not to load the content. If you use Javascript you can set the CSS of the table cells to show them or hide them. Link to comment Share on other sites More sharing options...
mjsulliv Posted February 22, 2010 Author Share Posted February 22, 2010 hello all, thanks for all your thoughs. At this point I'm going to use style= 'display: none'since that puts the data in the source but takes up no display space. But I'm curious about:If you use pure PHP you can simply choose not to load the content.How is that done?Thanks again --- Mike Link to comment Share on other sites More sharing options...
ShadowMage Posted February 22, 2010 Share Posted February 22, 2010 I want to be able to pass non-displayed data on a html page and use JavaScript to algorithmically load select-options with values from this data. The data source is a database table. My thought was to have php build a hidden table from which the JavaScript could pull the information.Then again if you're only loading the data so that JavaScript can populate a few select tags, why don't you just use PHP to build those select tags instead? Link to comment Share on other sites More sharing options...
mjsulliv Posted February 22, 2010 Author Share Posted February 22, 2010 Then again if you're only loading the data so that JavaScript can populate a few select tags, why don't you just use PHP to build those select tags instead?Hi. Because only some of the table data will be put into the selects and what gets picked in the first select will control what gets put in the second and the second controls the third and so on. --- Mike Link to comment Share on other sites More sharing options...
thescientist Posted February 22, 2010 Share Posted February 22, 2010 sounds like something PHP could do based on using conditional statements. Link to comment Share on other sites More sharing options...
ShadowMage Posted February 22, 2010 Share Posted February 22, 2010 Hi. Because only some of the table data will be put into the selects and what gets picked in the first select will control what gets put in the second and the second controls the third and so on. --- MikeAll of the data is coming from the database and being written with PHP anyway though. So, like thescientist said, you could do something like this:...//Construct first select...//Construct second selectif (condition) { //condition would be checking for the value of whatever data determines how this select is set up...//Select for a particular data value...} else {...//Select for a different data value...} You could also use a switch: $variable = "Data Value"; //This would be the value of the data from the DBswitch ($variable) {case "something": ... break;case "somethingElse": ... break;} Link to comment Share on other sites More sharing options...
mjsulliv Posted February 22, 2010 Author Share Posted February 22, 2010 But... The PHP is done on the server; its the action at the client that contorls what is selected, necessitating javascript. My understanding is that clients don't do PHP.--- Mike Link to comment Share on other sites More sharing options...
ShadowMage Posted February 22, 2010 Share Posted February 22, 2010 I getcha. But just to be sure.You load select1 with some data.A user selects an item from that data.Then you want to populate select2 based on what the user chose from select1.Correct?Well, if that's the case you could use AJAX. Link to comment Share on other sites More sharing options...
mjsulliv Posted February 23, 2010 Author Share Posted February 23, 2010 I getcha. But just to be sure.You load select1 with some data.A user selects an item from that data.Then you want to populate select2 based on what the user chose from select1.Correct?Well, if that's the case you could use AJAX.Correct.As to AJAX, I've not looked into it at all; maybe.--- Mike Link to comment Share on other sites More sharing options...
ShadowMage Posted February 23, 2010 Share Posted February 23, 2010 You might want to at least give it a look. AJAX can be a very powerful technique. Link to comment Share on other sites More sharing options...
thescientist Posted February 23, 2010 Share Posted February 23, 2010 and looks pretty cool when you use it! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.