Jump to content

Pass Hidden Data To Web Page


mjsulliv
 Share

Recommended Posts

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

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

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. Edited by jkloth
Link to comment
Share on other sites

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

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

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

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

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
All 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;}

Edited by jkloth
Link to comment
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...