jquery - How can i post a variable equal to the only "style = 'display: block'" dropdown menu? -
so have 6 dropdown menus in class called .receiver
, 1 visible based on selection of #type1
dropdown menu. depending on current value of #type
menu, appropriate .receiver
displayed. want post value of .receiver
dropdown menu display set "block". there selector can use this? tried program glitch
work creating user_receiver
variable , assigning value of program glitch
menu on change doesn't work.
here script:
$(document).ready(function() { var user_receiver; $("#type1").change(function() { $('#it1').css('display', 'none'); $('#operations1').css('display', 'none'); $('#logistics1').css('display', 'none'); $('#customerservice1').css('display', 'none'); $('#buyers1').css('display', 'none'); var type = $("#type1").val(); if (type == 'program glitch') { $('#it1').css('display', 'block'); user_receiver = ('#it').val(); document.write(user_receiver); } if (type == 'listing discrepancy') { $('#operations1').css('display', 'block'); } if (type == 'manufacturing discrepancy') { $('#buyers1').css('display', 'block'); } if (type == 'po discrepancy') { $('#logistics1').css('display', 'block'); } if (type == 'receiving discrepancy') { $('#logistics1').css('display', 'block'); } if (type == 'rma discrepancy') { $('#customerservice1').css('display', 'block'); } if (type == 'sales discrepancy') { $('#it1').css('display', 'block'); } if (type == 'shipping discrepancy') { $('#logistics').css('display', 'block'); } }); $("#sub").click(function() { var user_issue = $("#issue").val(); var user_priority = $("#priority").val(); var user_type = $("#type1").val(); $.post("bugreport.php", { receiver: user_receiver, issue: user_issue, priority: user_priority, type1: user_type, receiver: user_receiver }, function(data) { $("#result").html(data); }); document.getelementbyid('issue').value = ''; $('#type1').prop('selectedindex', 0); $('#priority').prop('selectedindex', 1); $('#it1').css('display', 'none'); $('#operations1').css('display', 'block'); $('#logistics1').css('display', 'none'); $('#customerservice1').css('display', 'none'); $('#buyers1').css('display', 'none'); }); });
body { padding: 0; margin: 0; } #box { padding: 5px; color: black; margin: 0 auto; border-style: solid; border-color: #0000e6; border-width: 2px; background-color: #58c6eb; width: 162px; height: 687px; float: left; border-radius: 10px; } .word { color: #0000e6; } .buttons { background-color: #ccffff; border-radius: 5px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <div id="box"> <h3 class="word" style="margin:10px 30px 30px 30px;">issue report</h3> <div class="word" style="width: 100px; margin-left: auto; margin-right: auto">type of issue:</div> <div style=" max-width: 150px; margin-left: auto; margin-right: auto; padding: 2px"> <form action="bugreport.php" method="post"> <select class="buttons" name="type1" id="type1" style='max-width: 150px;'> <?php $servername="localhost" ; $username="user" ; $password="pass" ; $database="db" ; $con=m ysqli_connect($servername,$username,$password,$database); if($con->connect_error){ die("connection failed " . $con->connect_error); } $sql1 = "select issue_name, issue_description issue"; $result = mysqli_query($con,$sql1); while ($row = mysqli_fetch_array($result)) { $issue = $row['issue_name']; $des = $row['issue_description']; echo " <option value='$issue' title='$des'>$issue</option>"; } ?> </select> </form> </div> <form action="bugreport.phpl" method="post"> <div id="buyers1" style="display:none;"> <select class="buttons receiver" name="buyers" id="buyers" style="margin: 0px 30px 0px 30px;"> <?php $sql="select first, last employee department_id = '1'" ; $result=m ysqli_query($con,$sql); while ($row=m ysqli_fetch_array($result)) { $name=$ row[ 'first'] . ' ' . $row[ 'last']; echo "<option value = '$name'>$name</option>"; } ?> </select> </div> </form> <div id="operations1" style="display:block;"> <form action="bugreport.php" method="post"> <select class="buttons receiver" name="operations" id="operations" style="margin: 0px 30px 0px 30px;"> <?php $sql="select first, last employee department_id = 2" ; $result=m ysqli_query($con,$sql); while ($row=m ysqli_fetch_array($result)) { $name=$ row[ 'first'] . ' ' . $row[ 'last']; echo "<option value = '$name'>$name</option>"; } ?> </select> </form> </div> <div id="it1" style="display:none;"> <form action="bugreport.php" method="post"> <select class="buttons receiver" name="it" id="it" style="margin: 0px 30px 0px 30px;"> <?php $sql="select first, last employee department_id = 3" ; $result=m ysqli_query($con,$sql); while ($row=m ysqli_fetch_array($result)) { $name=$ row[ 'first'] . ' ' . $row[ 'last']; echo "<option value = '$name'>$name</option>"; } ?> </select> </form> </div> <div id="customerservice1" style="display:none;"> <form action="bugreport.html" method="post"> <select class="buttons receiver" name="customerservice" id="customerservice" style="margin: 0px 30px 0px 30px;"> <?php $sql="select first, last employee department_id = 4" ; $result=m ysqli_query($con,$sql); while ($row=m ysqli_fetch_array($result)) { $name=$ row[ 'first'] . ' ' . $row[ 'last']; echo "<option value = '$name'>$name</option>"; } ?> </select> </form> </div> <div id="hr1" style="display:none;"> <form action="bugreport.html" method="post"> <select class="buttons receiver" name="hr" id="hr" style="margin: 0px 30px 0px 30px;"> <?php $sql="select first, last employee department_id = 5" ; $result=m ysqli_query($con,$sql); while ($row=m ysqli_fetch_array($result)) { $name=$ row[ 'first'] . ' ' . $row[ 'last']; echo "<option value = '$name'>$name</option>"; } ?> </select> </form> </div> <div id="logistics1" style="display:none;"> <form action="bugreport.html" method="post"> <select class="buttons receiver" name="logistics" id="logistics" style="margin: 0px 30px 0px 30px;"> <?php $sql="select first, last employee department_id = 6" ; $result=m ysqli_query($con,$sql); while ($row=m ysqli_fetch_array($result)) { $name=$ row[ 'first'] . ' ' . $row[ 'last']; echo "<option value = '$name'>$name</option>"; } ?> </select> </form> </div> <form action="bugdisplayandreply.html" method="post"> <label></label> <br> <textarea style="max-width: 156px; background-color: #f3f9ff; border-color: #0000e6;" cols="20" rows="34" name="issue" id="issue" placeholder="enter issue here" "></textarea></form><br> <div class="word " style="width: 50px; margin-left: auto; margin-right: auto ">priority:</div> <div style = "width: 70px; margin-left: auto; margin-right: auto; padding: 2px "> <form action="bugreport.html " method="post "> <select class = "buttons " name = "priority " id = "priority "> <option value = "low ">low</option> <option value = "regular " selected>regular</option> <option value = "high ">high</option> <option value = "urgent ">urgent</option> </select> </form></div> <div style = "width: 50px; margin-left: auto; margin-right: auto; padding: 2px "> <input class = "buttons " type ="submit " name = "sub " value = "submit " id = "sub "></div> <div id="result "></div> </div>
how using jquery(':visible')
?
(read documentation performance implications!)
Comments
Post a Comment