reverend boltron
Senior member
Question: How would I use JS and PHP together to dynamically repopulate my select boxes?
Background info:
I'm still a major newbie using PHP and JavaScript and pretty much all scripting languages. I have a semi strong C++ background and I know BASIC as well, so everything isn't absolutely foreign to me.
Right now, I have my website built and performing pretty decent. I want to switch over from HTML to PHP. I've recently discovered how cool this language is, and I want to start using it to it's potential.
I have select boxes that are chained, but they're chained using JavaScript, compliments of a nice JS library that I found. Originally I had a list of bible verses that I have highlighted in my bible display when you select the verse. The boxes automatically repopulate based on what book you're in, and then from what chapter you're in.
What I want to do is add functionality for different users. If I have several different people give me a list of their verses, I want to be able to select a user, and have the books, chapters, and verses repopulate from there.
What I want to cut down on though, is the amount of initial loading time. I have over 1,300 different verses in my life, and I'm sure that the other people will have over 500 as well.
The page uses PHP and MySQL to fetch the verses from a database and display the result on a page (thanks W3Schools!), so that doesn't have an impact on the original loading time.
Downloading a huge JS file can take a long time, so I wanted to use JS and PHP together to repopulate my select boxes. If someone chooses a user, then a JS function will send that off to the server, which goes through a PHP switch statement, and sends back the HTML/JS for that specific user for the box population.
I set it up one way using MySQL but it would take about 30 seconds to fetch the info and send it back, that isn't an acceptable amount of time. I would expect at most two to two and a half seconds.
Here is the link to the JS file that works with the PHP file getverse.js
Here is my code thus far...
Background info:
I'm still a major newbie using PHP and JavaScript and pretty much all scripting languages. I have a semi strong C++ background and I know BASIC as well, so everything isn't absolutely foreign to me.
Right now, I have my website built and performing pretty decent. I want to switch over from HTML to PHP. I've recently discovered how cool this language is, and I want to start using it to it's potential.
I have select boxes that are chained, but they're chained using JavaScript, compliments of a nice JS library that I found. Originally I had a list of bible verses that I have highlighted in my bible display when you select the verse. The boxes automatically repopulate based on what book you're in, and then from what chapter you're in.
What I want to do is add functionality for different users. If I have several different people give me a list of their verses, I want to be able to select a user, and have the books, chapters, and verses repopulate from there.
What I want to cut down on though, is the amount of initial loading time. I have over 1,300 different verses in my life, and I'm sure that the other people will have over 500 as well.
The page uses PHP and MySQL to fetch the verses from a database and display the result on a page (thanks W3Schools!), so that doesn't have an impact on the original loading time.
Downloading a huge JS file can take a long time, so I wanted to use JS and PHP together to repopulate my select boxes. If someone chooses a user, then a JS function will send that off to the server, which goes through a PHP switch statement, and sends back the HTML/JS for that specific user for the box population.
I set it up one way using MySQL but it would take about 30 seconds to fetch the info and send it back, that isn't an acceptable amount of time. I would expect at most two to two and a half seconds.
Here is the link to the JS file that works with the PHP file getverse.js
Here is my code thus far...