Good day, I have such a problem: I make a selection from the database, the links and the container with the form, the form is initially hidden, and when I clicked on the link, it should open, so only the first link works, and the rest does not, hides and closes the block via jQuery .

echo "<div class='doctor_z_4'>" . "<a href='#' id='fa'>" . $talon_time['date_talon'] . "\n" . substr($talon_time['time_talon_tima'], 0, 5) . " - " . "</a>" . "<p>" . $talon_time['talon_status_text'] . "</p>" . "</div>"; echo "<div class='line'></div>"; echo "<div id='block' style='display:none;'>"; echo "<div class='zap_tal_1'>Здравствуйте! " . "Ваш талон № " . "<b class='zap_tal_2'>" . $talon_time['id_talon'] . "</b>" . "</div>"; echo "<div class='zap_tal'> Ваш врач: " . "<b class='zap_tal_2'>" . $mass_doctor['last'] . "\n" . $mass_doctor['first'] . "\n" . $mass_doctor['middle'] . "</b>" . "</div>"; echo "<div class='zap_tal'> День приёма: " . "<b class='zap_tal_2'>" . $talon_time['date_talon'] . "</b>" . "</div>"; echo "<div class='zap_tal'> Время приёма: " . "<b class='zap_tal_2'>" . substr($talon_time['time_talon_tima'], 0, 5) . "</b>" . "</div>"; echo "<div class='line'></div>"; echo "<form method='post' action='lesson20.php'>"; echo " <div class='formochka'>"; echo " <div class='formochka_text'>"; echo " <p>Имя ребёнка:</p>"; echo " </div>"; echo " <div class='formochka_input'>"; echo " <input class='name_reb' type='text' name='name_reb'/>"; echo " </div>"; echo " </div>"; echo " <div class='formochka'>"; echo " <div class='formochka_text'>"; echo " <p>Фамилия ребёнка:</p>"; echo " </div>"; echo " <div class='formochka_input'>"; echo " <input class='name_reb' type='text' name='fam_reb'/>"; echo " </div>"; echo " </div>"; echo " <div class='formochka'>"; echo " <div class='formochka_text'>"; echo " <p>Отчество ребёнка:</p>"; echo " </div>"; echo " <div class='formochka_input'>"; echo " <input class='name_reb' type='text' name='middle'/>"; echo " </div>"; echo " </div>"; echo " <div class='formochka'>"; echo " <div class='formochka_text'>"; echo " <p>Домашний адрес:</p>"; echo " </div>"; echo " <div class='formochka_input'>"; echo " <input class='name_reb' type='text' name='adres_dom'/>"; echo " </div>"; echo " </div>"; echo " <div class='formochka'>"; echo " <div class='formochka_text'>"; echo " <p>Домашний телефон:</p>"; echo " </div>"; echo " <div class='formochka_input'>"; echo " <input class='name_reb' type='text' name='tel_dom'/>"; echo " </div>"; echo " </div>"; echo " <div class='formochka'>"; echo " <div class='formochka_text'>"; echo " <p>Сотовый телефон:</p>"; echo " </div>"; echo " <div class='formochka_input'>"; echo " <input class='name_reb' type='text' name='te_sot'/>"; echo " </div>"; echo " </div>"; echo " <div class='formochka'>"; echo " <div class='formochka_text'>"; echo " <p>Укажите пол:</p>"; echo " </div>"; echo " <div class='formochka_input'>"; echo " <input type='radio' name='sex' value='M' /> Мужской \n"; echo " <input type='radio' name='sex' value='G' /> Женский "; echo " </div>"; echo " </div>"; echo " <div class='formochka'>"; echo " <div class='formochka_text'>"; echo " <p>Ваш E-mail:</p>"; echo " </div>"; echo " <div class='formochka_input'>"; echo " <input class='name_reb' type='email' name='mail'/>"; echo " </div>"; echo " </div>"; echo " <input type='submit' value=' Записаться ' />"; echo "</form>"; echo "</div>"; 

And here is jQuery

 <script> $('#fa').toggle(function () { $('#block').show('bounce', 500); }, function () { $('#block').hide('bounce', 500); }); </script> 
  • one
    @ dimka1judo, are you kidding? To format the code, select it with the mouse and click on the button 101010 of the editor. - xEdelweiss

2 answers 2

Judging by your code, you have all the links have the same id, but this should not be. Change to class.

Addition

 $('.fa').toggle(function () { $(this).parent().siblings('.block').show('bounce', 500); }, function () { $(this).parent().siblings('.block').hide('bounce', 500); }); 
  • I changed everything to classes, but now all the truth links work, but when you click on any of them, all the blocks appear at once, but how to make something appear only 1, active chtoli - dimka1judo
  • Completed in response - Deonis

On the subject of the question, so, in a vskidku, because the html code was difficult to parse, in javascript you select based on the id of the element, which should be unique on the page, so your event is triggered only on one element

PS Dude, what for every line of html to write echo? Vseravno, in your style, all html on the page will be without indents and hyphenations. If you strongly want to print html from a php script, then no one forbids you to use only one echo first, and then a whole block of formatted code with inserted variables, and the source html code formatting will appear on the page and transmit the variables. Etc:

 echo '<div class="header"> <ul id="nav"> <li> <a href="' . {$data['main_url']} . '">' . {$data['main_label']} . '</a> </li> <li> <a href="' . {$data['about_url']} . '">' . {$data['about_label']} . '</a> </li> <li> <a href="' . {$data['other_url']} . '">' . {$data['other_label']} . '</a> </li> </ul> </div>';