Hi,

I need to populate a js array so I can use the results when running the "onchange" of an HTML form's "select" clause.

Is there a way of doing this?

Basically, I have a Select tag on a web page. It is populated with options. When the user selects an item from the dropdown list I need to fill in (via javascript onchange i suppose) an Input field on the page. The value I need to drop into this field comes from a mysql db.

The only solution I can think of is to populate a js array before the user selects his choice (don't know how do to this in realtime).

I'm at a loss and don't know how to proceed.

Please help!

    What you want is can be done in 2 ways, the first is an AJAX solution, which can get complicated and unless you know what I am talking about, the other easier approuch is to invoke a submit() on onchange and pass a get variable to the header which you catch on top of your page with php, which will supply you with the variables from the database.

      Thanks for your input!

      1. You're right, I have no idea what Ajax is except that I've used it to clean the toilet 🙂

      2. I've tried the submit(), because I'm modifying a calendare app (Thyme from extrosoft.com) the submit doesn't work.

      Any other ideas?

      Thanks

        2 would always work, do something like this:

        <form method="get">
        <select onchange="getElementById('getMyValuesFormMysql').value=1; submit();">
        <input name=getMyValuesFormMysql type=hidden />
        </form>

        so in the top in your page you do:

        <?php
        if (!empty($_GET['getMyValuesFormMysql'])) {
        //put your database stuff here
        }
        ?>

          Thanks WIlliam,

          I had tried something like this before and it didn't work. I think it's because the php which generates the calendar creates it's own form as shown below. All the included modules are wrapped by this form. I can't create my own form, only form elements.

          <form method="POST" action="/thyme2/index.php" enctype='multipart/form-data' name="EventForm" onSubmit='return form_submit_EventForm()'>
          <input type=hidden name="ecalendar" value="">

          Do I make sense? That's why I'm looking for another way. I'm a newbie which makes it more difficult. I'm quite frustrated not knowing how to crack this one.

          GIlles

          Gilles

            Write a Reply...