• MySQL via PHP and JavaScript

    Author
    Topic
    #440173

    Question: populating on the fly created select boxes through PHP by retrieving data stored in MySQL tables is essentially a three line piece of code. Now… .Can someone suggest a way to connect the data to select boxes already in the document ?.Thanks in advance…

    Viewing 0 reply threads
    Author
    Replies
    • #1053823

      I’m not sure what you’re asking. You want to post back to the server, or you want to add data to the page using JavaScript without going reloading the entire page, or ???

      • #1053829

        I want to return data back to the server. The select boxes are part of a form. Once the boxes have been populated, data is locally processed via JS and then saved back to the server. Once I apply the mysql_fetch_array function and have access to all the members of each and every row….how do I transfer this info to the -existing- boxes so I can operate with the data?.

        • #1053837

          I still might not have the complete picture, but… if “the -existing- boxes” refers to your elements, you can use JavaScript to change them in either of two ways. The simpler is to remove all the nodes from the and add new nodes from your array; the more complicated would be to loop through and insert/delete based on a comparison with your array. Does this seem as though it is heading in the right direction?

          • #1054268

            Correct. The simple option is the one I am pursuing but…the question is how do I connect the nodes of the array (that I managed to get through PHP) to the options of the select boxes that are part of the html page. The most universal DOM compliant approach is document.getElementById(“selectName’).options…but this is accessible through JavaScript only..therefore….how do I turn the elements of the array that are floating in cyberspace into options on the select boxes ?. Thanks again in advance.

            • #1054471

              (Edited by jscher2000 on 02-Mar-07 11:07. )

              I have been assuming you have the page on the client side and want to update locally using JavaScript. However, your post has me confused.

              * I don’t think PHP is relevant on the client side. If you have an array it needs to be a JavaScript data structure, regardless of the type of server-side page that returned the array and regardless of the technology used to fetch it. (Added: This looks like a handy source example for the DOM methods: http://www.mredkj.com/tutorials/tutorial005.html%5B/url%5D.)

              * If you are referring to the page on the server that you are processing before returning it to the client (postback to self) then just use the ordinary PHP syntax to create options from scratch. There is no DOM to manipulate in PHP script, only when the page is in the browser.

    Viewing 0 reply threads
    Reply To: MySQL via PHP and JavaScript

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: