CodeIgniter Forums
CI and Jquery Loop wont work... - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: CI and Jquery Loop wont work... (/showthread.php?tid=19752)

Pages: 1 2


CI and Jquery Loop wont work... - El Forum - 06-17-2009

[eluser]1mr3yn[/eluser]
Sorry im a newbie in jquery..


CI and Jquery Loop wont work... - El Forum - 06-17-2009

[eluser]1mr3yn[/eluser]
Hi guyz.,
Can someone tell,. why jquery wont work., on a menu within a loop.,

foreach( $partners as $p_field) {

print "<span class=\"partners\">";
print "<a href="#" id="showdetails">";
print $p_field->name. "</a> </span><br>";
}

// script
$("#showdetails").click(function() {
runEffect();
return false;
});

The menu is from the database., I want every time I click a menu,. an effect occur., but my problem is that
the effect works on the first menu only., the and when I click the others menu aside from the first,, they ignore the effects.,. is there something wrong with my code???


CI and Jquery Loop wont work... - El Forum - 06-17-2009

[eluser]Thorpe Obazee[/eluser]
Code:
foreach( $partners as $p_field) {

      print "<span class=\"partners\">&lt;a class=\"showdetails\"&gt;$p_field->name</a></span>";
  }

// script
function runEffect(){
    // run effect
}

$('document').ready(function(){
     $(".showdetails").click(function(e) {
            e.preventDefault();
            runEffect();
      });
});

url is not an html tag


CI and Jquery Loop wont work... - El Forum - 06-17-2009

[eluser]1mr3yn[/eluser]
That url means <a ></a>, this forum changes that.,.
I try your code but it is still the same..


CI and Jquery Loop wont work... - El Forum - 06-17-2009

[eluser]1mr3yn[/eluser]
by the way.,. It WORKS!!! thanks.,.
I just change the id into class,,,

COOL!!!!!!


CI and Jquery Loop wont work... - El Forum - 06-17-2009

[eluser]Thorpe Obazee[/eluser]
glad you got it working Smile


CI and Jquery Loop wont work... - El Forum - 06-17-2009

[eluser]1mr3yn[/eluser]
Thanks a lot.,. but here's the other problem.., how can I pass the value of that menu to the form within the same page,??


CI and Jquery Loop wont work... - El Forum - 06-18-2009

[eluser]Thorpe Obazee[/eluser]
[quote author="r3yn" date="1245321509"]Thanks a lot.,. but here's the other problem.., how can I pass the value of that menu to the form within the same page,??[/quote]

What do you mean?


CI and Jquery Loop wont work... - El Forum - 06-18-2009

[eluser]1mr3yn[/eluser]
I mean I need to pass this variable '$p_field->name' to the value of &lt;input type="text"&gt; fields within the same page.,

So that when I click a menu(from a loop)., a dialog box can determined what menu I had clicked, and pass to a php variable so that active records can be done.,.


CI and Jquery Loop wont work... - El Forum - 06-18-2009

[eluser]Thorpe Obazee[/eluser]
Code:
$('.showdetails').click(function(e){
            e.preventDefault();
            $('#yourinput').val($(this).text());
        });

I'm guessing this would work.