Hi, I wrote a code to show a div element(shareform) when a link is clicked and to hide it when the link is clicked again. I have many Forms under which this link 'Share' will be displayed. If i have only one Form, this code works fine. That is, initially the 'shareform' element is hidden and when I click the link, it is shown and when I click the link again the 'shareform' is hidden.
If I have 2 forms, the 'shareform' element for the second Form is not hidden initially. Isn't this $('#shareform').hide(); suppose to hide the form for all the Share links?
And also, when I click the second "share" link, the 'shareform' is shown and hidden for the first "share" link. What Am I doing wrong? Can someone help me?
var flag=0;
$('#shareform').hide();
$(".Share").click(function(){
if(flag==1){
$('#shareform').hide('fast');
flag=0;
}
else{
$('#shareform').show('slow');
flag=1;
return false;
}
});//.Share click
$("#shareform .button").click(function(){
$("#userList option:selected").each(function(){
selected_value[i]=$(this).val();
alert(selected_value[i]);
i++;
});
});
<li id="Share<?php echo $r['Form']['id']?>">
<a href="#" class="Share">Share</a>
<form action="/cake_1_2/forms/share/<?=$formid?>/<?=$userid?>" method="post" name="shareform" id="shareform">
<p>Select the users with whom you want to share the Form</p>
<select id="userList" name="userList" multiple>
<?php foreach($users as $user){ ?>
<option value="<?=$user['User']['name']?>"><?=$user['User']['name'];?></option>
<?php }?>
</select>
<input type="submit" class="button" value="Share"/>
</form>
</li>
EDIT: I'm sorry, actually i want to hide only the id element share_form,not the class 'Share' coz that class refers to the link alone. also i changed share_form to shareform,it still doesnt work.
EDIT 2:
Ok, I've changed id to class,i.e class='shareform'. Now the shareform class is hidden initially. But if I click the 'Share' link, the 'shareform' class is showed for both the forms.