CodeIgniter Forums

Full Version: CI and Jquery Loop wont work...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

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

El Forum

[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???

El Forum

[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

El Forum

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

El Forum

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

COOL!!!!!!

El Forum

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

El Forum

[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,??

El Forum

[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?

El Forum

[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.,.

El Forum

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

I'm guessing this would work.
Pages: 1 2