javascript - How to create individual IDs in a PHP loop -
i have developed php loop creates register form everyday each user in database. each form has 1 div contains variety of dropdowns , placed directly on 1 shows has has been submitted day. when 1 of dropdown boxes selected have used jquery make top div disappear , show answer on div below. if mistake made there reset button puts x database.
i have created php query finds recent input each user every day (whether x or registered day). echoed div on top div (i use css hide it).
what want have happen when loads page show people have been registered day. want having function hides top div who's string length >2. have tried multiple ways can't work. there way create unique id's , transfer these jquery?
i have attached simplified version of code below shows have far. appreciated.
i have tried using counter think have implemented wrong. can see how fix can call unique ids? here script have tried.
<script> $(document).ready(function() { if ($("#needed<?= $i ?>").text().length > 3) { $("#needed<?= $i ?>").parentsuntil(".submitted").addclass("hidediv"); $("#needed<?= $i ?>").parentsuntil(".submitted").removeclass("showdiv"); } });
<!doctype html> <html> <head> <?php include 'dbconnection.php'; ?> <link href="hidphptest.css" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"> </script> <script> $(document).ready(function(){ $(".cars").change(function(){ $(this).parentsuntil(".submitted").addclass("hidediv"); $(this).parentsuntil(".submitted").removeclass("showdiv"); }); }); </script> <script> $(document).ready(function(){ $(".go45").click(function(){ $(this).siblings().addclass("showdiv"); $(this).siblings().removeclass("hidediv"); }); }); </script> <script> $(document).ready(function() { if ($("#needed<?= $i ?>").text().length > 3) { $("#needed<?= $i ?>").parentsuntil(".submitted").addclass("hidediv"); $("#needed<?= $i ?>").parentsuntil(".submitted").removeclass("showdiv"); } }); </script> <body> <br> <form method="post" action="testplace3.php"> <select name="classu" > <option disabled="disabled" selected="selected">select class</option> <?php $selectclass=$connect->query("select distinct class `firstnametest` "); while($rows=$selectclass->fetch_array()) { ?> <option value="<?php echo $rows['class']; ?>"><?php echo $rows['class']; ?> </option> <?php } ?> <input type="submit" value="add group" style="width: 317px; height: 45px"/> </select> </form> <?php $query=mysqli_query($connect,"select * firstnametest class = 'group1'" ); // initiate counter variable $i = 1; while ($row=mysqli_fetch_array($query)) { ?> <div class="submitted "> <button id="butest" type="button" class="go45 btn btn-info " value="<?php echo$row["id"]; ?>">go back</button> <div class="todo "><br><span id="needed<?= $i ?>"><?php echo$row["surname"]; ?></span><br> <select class="cars" > <option disabled="disabled" selected="selected">group </option> <option value="group 1">group 1</option> <option value="group 2">group 2</option> <option value="group 3">group 3</option> <option value="group 4">group 4</option> </select> <br> <div > </div> </div> </div> <!-- counter increment --> <?php $i++; } ?> </body> </html>
if reading right, script problem.
<script> $(document).ready(function() { if ($("#needed<?= $i ?>").text().length > 3) { $("#needed<?= $i ?>").parentsuntil(".submitted").addclass("hidediv"); $("#needed<?= $i ?>").parentsuntil(".submitted").removeclass("showdiv"); } }); </script>
i don't know how $(document).ready(function()
bit works code creating has #needed
, $i null when page generated php. guess working on #needed
div. may need loop through divs , hide them in function().
Comments
Post a Comment