开发者

Possible to populate a php/mysql call with a value selected within form on same page?

I have a form which has two inputs. The first input allows a user to select two values (either 1 or 2). My second input allows the user to select a ra开发者_如何学运维nge of available dates (which is populated from a separate php/mysql query).

I would like to achieve the following:

  1. At page load, the second box is simply 'non-clickable'. The user must make a selection in part 1.

  2. Once a user makes a selection in box 1, the values of part 2 are dynamically created accordingly as the value selected from part 1 (either 1 or 2) is used in a php pdo prepared statement into a mysql database.

is this possible?


Yes, it's very achievable using jQuery . When the page is ready, you'd disable the second input, and bind it being enabled to the first one being filled out. Then you'd use the jquery ajax function to get the data for the next one and populate it that way.

You should probably read a basic jQuery tutorial, then read the documentation for the specific functions like ajax().

Trust me, you'll be really glad to know jQuery as it comes in handy for all types of things, especially situations like these where you need to setup somewhat complex dynamic forms with ajax calls to your server along the way.


Yes you want to use ajax. I would advice you to take a look at jquery.

Jquery would help you to work around doing the ajax calls and manipulating elements in your page.

Your example should fairly simple to implement using the library.


window.onload = function() {

   var input1 = document.getElementById('input1'),
       input2 = document.getElementById('input2');

   input2.disabled = true;

   input1.onchange = function() {
       input2.disabled = false;
       // Build whatever you want here
       input2.value = 'whatever';
   }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜