How to Populate Select from PHP Function in WordPress
-
I have a form shown below:
<?php $list_id = $db_connect->get_results($db_connect->prepare('SELECT * FROM users WHERE wp_ID= %d AND svr_region=%d', $wpid, 1)); ?> <form name = "reset_data" action="<?php the_permalink(); ?>" method="post"> <select id = "select_id" name="select_id" required> <option value="" > - Chose ID - </option> <?php foreach ($list_id as $list_id) { $get_list_id = $list_id->ID; $get_list_name = $list_id->name; echo '<option value="' . $get_list_id . '" >[' . $get_list_id . '] ' . $get_list_name . '</option>'; } ?> </select> <select id = "select_role" name="select_role" > <option value="" > - Chose Role - </option> <?php $get_role = GetRoleList($_POST['select_id']); echo $get_role; ?> </select> <input type="submit" value="Get Data! »"/> </form>
How do I create a JQuery or Ajax to disable
#select_role
if#select_id
has an empty value.#select_id
value type is Integer, and after#select_id
chosen, it will execute a PHP functionGetRoleList ( $_POST['select_id'] )
and returns the result like this'<option value="' . $nick_str . '" >' .$nick_str. '</option>'
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to Populate Select from PHP Function in WordPress’ is closed to new replies.