Welcome Guest, Not a member yet? Register   Sign In
how to i can access id data from database looping with jquery and save to database
#1

[eluser]tusukgigi[/eluser]
example
Controllers---->>>>


function loopdb(){
$data['users'] = $this->MUsers->getAllUsers();
$this->load->vars($data);
$this->load->view('profile/v_loopdb');
}

Views----->>>>

<html>
<head>
[removed][removed]

[removed]
$(document).ready(function(){
$('.theclickers').click(function(){
$('#myForm').slideToggle();
});
});
[removed]
<head>
<body>


<?php
if(count($users)){
foreach($users as $key => $lists){
?>
<a href='#' class='theclickers'>&lt;?php echo $lists['nick'];?&gt;</a><br />
&lt;form action="" method="post" style='display:none;' id='myForm'&gt;
&lt;input type='text' name='toDown' id='toDown' /&gt;
&lt;input type='submit' name='submit' value='save'&gt;
&lt;/form&gt;
&lt;?php
}
}
?&gt;

&lt;/body&gt;
&lt;/html&gt;


-----------------------------------------------------
with the above code, I can only access a single id.
if another link is clicked
id only the first course that appears


how to i can access id data from database looping with jquery and save to database
#2

[eluser]jmadsen[/eluser]
I'm a little confused, but I think I see what you are after:

You are giving the same id to all of your forms ("myForm"), so jquery's $(’#myForm’).slideToggle(); always works on the first one.

Try adding a counter or using something from your data to make id's like: "myForm_".$i , and then clicking a submit button named id="submit_".$i ...you get the idea? I'm not clear if your jquery is just sample code, or what you are trying to do with it (and what 'theclickers' is)

Hope that helped
#3

[eluser]bl00dshooter[/eluser]
Simple question, simple solution: Use a class instead of an ID. The purpose of an ID is to be unique on the page, so you shouldn't use it more then 1 time.

Change:

Code:
&lt;form action=”” method=“post” style=‘display:none;’ id=‘myForm’&gt;

to

Code:
&lt;form action=”” method=“post” style=‘display:none;’ class=‘myForm’&gt;

and change your jQuery from:

Code:
$(document).ready(function(){
  $(’.theclickers’).click(function(){
    $(’#myForm’).slideToggle();
  });
});

to:

Code:
$(document).ready(function(){
  $('.theclickers').click(function(){
    $('.myForm').slideToggle();
  });
});

If you have any trouble with adapting your code, just say.
#4

[eluser]jmadsen[/eluser]
No, I don't think that works for what he is saying.

If I understand tusukgigi right, he is clicking on any button, but the first form is always being affected. This is because the forms all have the same id, and so jquery will always take the first from the collection.

Yes, make a class like bl00dshooter said, but that will only make your code valid. It won't specify WHICH form to toggle.

Better will jquery will be something like (sorry, untestedSmile

Code:
$(document).ready(function(){
  $('#submit').click(function(){
    $('this').parents('form:first').slideToggle();
  });
});

You should still consider giving unique id's to forms like I mentioned if you need to reference them individually later.




Theme © iAndrew 2016 - Forum software by © MyBB