Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] jquery ajax load() with dropdown (select) value
#1

[eluser]boony[/eluser]
Hmm Sometimes it seems harder to think of an appropriate title then solving the original problem...but I digress Smile

I've just lost 6 precious hours of my life, and I ain't got that many left, trying to get an ajax jquery load happening using a drop down select value.

I have got it working fine using a single input field as in the follwing:
Code:
$(document).ready(function() {
          
  $("#sendit").click(function() {
        
     $("#showmember").load("<?php echo site_url(); ?>index.php/users/members",
     {
        id: postid.value
     });
        
   });
});

The view is simply this:
Code:
<form action="<php echo site_url(); ?>/users/members" method="POST">
<input id="postid" name="postid" />
<input type="submit" name="sendit" id="sendit">
</form>
<div id="showmember"></div>
There is an on click = return false in the submit but its not showing in the code here :-S
However, I want my users to select a member from a dynamically generated dropdown. Obviously, I got the drop down working like this:
Code:
echo form_open(&lt;?php $base;?&gt;'users/get_member');
$dropdown = array();
foreach ($members as $list)
{
  $dropdown[$list->idmember] = $list->member_lname;}
  echo form_dropdown('member_lname', $dropdown);
  &lt;input type="submit" name="sendit" id="sendit"&gt;  
  echo form_close();
I've tried a number of ways but I can't seem to post to the controller the value of the selected option.

Any help on this would be much appreciated and maybe I can stop banging my head.


Whoa, hold yer horses!. I stopped banging my head, went to the..., and the redid it and got it working.
Code:
$(document).ready(function() {
            
$("#sendit").click(function() {
        
$("#showmember").load("&lt;?php echo site_url(); ?&gt;index.php/message/members",
{
  id: $('select option:selected').val()
});
        
});

I'm pretty sure I did this before but maybe did something wrong - well not maybe Sick




Theme © iAndrew 2016 - Forum software by © MyBB