2016-05-18 5 views
-2

私はphpファイルでjavascriptを書いていますが、javascriptを使用してドロップダウンからの入力を選択したいのですが、ドロップダウンのデフォルト値はSELECTで、フォームを送信すると私は選択してくださいLableの値下がり。機能Javascriptフォームのサブミットでは動作しません

と、次のJavaScriptで私が行っ

<?php 
    include("$_SERVER[DOCUMENT_ROOT]/riteshproject/config.php");   ?> 

<?php  if(isset($_POST['empsubmit'])) {   
if(isset($_POST['areaname']) && isset($_POST['flat']) && 
isset($_POST['rentsale']))  { 

      $an=$_POST['areaname'];    $flat=$_POST['flat']; 
      $rentsale=$_POST['rentsale']; 

         $_SESSION['an']=$an;   $_SESSION['flat']=$flat;   $_SESSION['rentsale']=$rentsale;   } 
      } if(isset($_REQUEST['unsetsession'])) {  session_destroy();; 
       header('location:home.php');  break; } ?> 


<!DOCTYPE html> <html lang="en"> <head> <title>Shree Shree 
Property,Kolhapur</title> <meta charset="utf-8"> <meta 
name="viewport" content="width=device-width, initial-scale=1"> 
<link rel="stylesheet" type="text/css" href="home.css"> 
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> 
<script 
src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
<style> 
    /* Remove the navbar's default margin-bottom and rounded borders */ 
    .navbar { 
     margin-bottom: 0; 
     border-radius: 0; 
    } 

    /* Set height of the grid so .sidenav can be 100% (adjust as needed) */ 
    .row.content {height: 450px} 

    /* Set gray background color and 100% height */ 
    .sidenav { 
     padding-top: 20px; 
     background-color: #f1f1f1; 
     height: 100%; 
    } 

    /* Set black background color, white text and some padding */ 
    footer { 
     background-color: #555; 
     color: white; 
     padding: 1em 15px;  margin-top: 50px; 
     border-radius: 0; 
    } 

    /* On small screens, set height to 'auto' for sidenav and grid */ 
    @media screen and (max-width: 767px) { 
     .sidenav { 
     height: auto; 
     padding: 15px; 
     } 
     .row.content {height:auto;}  .active { background-color: #00bfff; } 
    } .col-sm-2{background-color: gray;} .col-sm-8{background-color: #e0e0eb; border-radius: 25px;} 
    .mainBlock4{background-color: gray; overflow: scroll; height: 
220px;}  .mainBlock5{background-color: gray; overflow: scroll; 
height: 240px;}   th{text-align: center; background-color:black; 
color:white;} .td1{color:black;} 
     .tr1:nth-child(even) { 
    background-color: #e0e0eb; } .trclose{}  .closebutton{ border-collapse: collapse;}  .button { 
    background-color: black; 
    border-radius: 10px; 
    color: white; 
    padding: 0.1px 8px; 
    text-align: center; 
    text-decoration: none; 
    display: inline-block; 
    font-size: 14px; 
    margin: 2px 2px; 
    cursor: pointer; border: 2px solid red;}   .button:hover { 
    background-color: gray; /* Green */ 
    color: white; 

     </style> </head> <body> 

<nav class="navbar navbar-inverse"> <div class="container-fluid"> 
    <div class="navbar-header"> 
     <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar"> 
     <span class="icon-bar"></span> 
     <span class="icon-bar"></span> 
     <span class="icon-bar"></span>       
     </button> 
     <img src="../riteshproject/logo.png" align="center" style="width:70px;height:50px;"> 
    </div> 
    <div class="collapse navbar-collapse" id="myNavbar"> 
     <ul class="nav navbar-nav"> 

     <li><a href="../riteshproject/home.php" class="active">Home</a></li>  <li class="current" id="dddd"><a 
href="../riteshproject/aboutus.php" >About US</a></li>  <li><a 
href="#">Contact US</a></li> 
     <li><a href="#">Add Property</a></li>  <li><a href="#">Luxarious Property</a></li>   <li><a href="#">Property For 
Sale</a></li>  <li><a href="#">Other Services</a></li> 
      </ul> 
     <ul class="nav navbar-nav navbar-right"> 
     <li><a href="../riteshproject/Login/login.php"><span class="glyphicon glyphicon-log-in"></span><img 
src="../riteshproject/login1.jpg" width="60" height="25"></a></li> 
     </ul> 
    </div> </div> </nav> <div class="container-fluid text-center">  <div class="row content"> 
    <div class="col-sm-2 sidenav" align="center" id="2"> 
      <head> 
     <title></title> 
     <script type="text/javascript"> 
      var picPaths = ['../riteshproject/img/prop1.jpg','../riteshproject/img/prop2.jpg','../riteshproject/img/prop3.jpg','../riteshproject/img/prop4.jpg', 
          '../riteshproject/img/prop5.jpg']; 
      var curPic = -1; 
      //preload the images for smooth animation 
      var imgO = new Array(); 
      for(i=0; i < picPaths.length; i++) { 
       imgO[i] = new Image(); 
       imgO[i].src = picPaths[i]; 
      } 

      function swapImage() { 
       curPic = (++curPic > picPaths.length-1)? 0 : curPic; 
       imgCont.src = imgO[curPic].src; 
       setTimeout(swapImage,2000); 
      } 

      window.onload=function() { 
       imgCont = document.getElementById('imgBanner'); 
       swapImage(); 
      } 
     </script> 

    </head> 
    <body> 
      <div> 
      <img id="imgBanner" src="" alt="" /> 
      </div> 
    </body> 
     <div> 

     <p><a href="#">Link</a></p> 
     <p><a href="#">Link</a></p> 
     <p><a href="#">Link</a></p> 
     </div> 

    </div> 
    <div class="col-sm-8 text-left">  <form action="" method="POST" onsubmit="notSELECT()"> 
     <table><tr><td><h4><b>Welcome To Shree Shree Property,Kolhapur</b></h4></td></tr></table> 
     <hr> 
     <h5><b><i><marquee width="365px" height="10px" direction=slide BEHAVIOR=ALTERNATE left:355px>Search Property in 
kolhapur... </marquee></i></b></h5> 
     </hr> 
     <table>  <tr> </tr>  <tr> </tr>  <tr> <td width='35px'></td>  <td> 
     <select name="rentsale" id="rentsale" value="select"> 
            <option>RENT</option> 
            <option>SALE</option> 
               </select> 
    </td> 
     <td><input type="radio" name="radio" value="flat" checked>FLAT</td> 
    <td width='35px'></td>  <td><input type="radio" name="radio" value="Bungalo">Bungalow</td>  </tr> <tr height="60px"> 

         <td height="20px" />Area 
         <td style="text-align:left"> 

            <select name="areaname" id="areaname" value="select" class="NotEmpty"> 
            <option value="SELECT" style="display:none">SELECT</option> 
             <?php 

              $query="select code,areaname from areamaster"; 
              $query_run=mysql_query($query); 
              mysql_num_rows($query_run); 

              while($row=mysql_fetch_assoc($query_run)) 

              { 
              ?> 

              <option value="<?php echo $row['areaname']?>"><?php echo $row['areaname']?></option> 
              <?php 
              } 
             ?> 
            </select> 
          </td> 
          <td></td> 
          <td>Flat</td> 
          <td style="text-align:left"> 

            <select name="flat" id="flat" value="select"> 
            <option value="SELECT" style="display:none">SELECT</option> 
             <?php 

              $query="select flat from flatmaster"; 
              $query_run=mysql_query($query); 
              mysql_num_rows($query_run); 

              while($row=mysql_fetch_assoc($query_run)) 

              { 
              ?> 

              <option value="<?php echo $row['flat']?>"><?php echo $row['flat']?></option> 
              <?php 
              } 
             ?> 
            </select> 
          </td> 
    </tr> <tr> 
     <td> 
     </td> 
     <td> 
     </td> 
     <td> 
      <input type="submit" name="empsubmit" style="width:75" id="submit" value="Search" class="button" onclick="showDiv()"> 
     </td>  </tr> </table> </form> 
    <?php  if(isset($_SESSION['an']))  { 

     ?> 
     <div class="heddendiv" width="30px"> 
     <html><b> 
     Property Found for your search...</b> 
       <div Class="mainBlock4" style="width:100%"> 
          <form name="leavesanction" action="" method="POST" onsubmit="notSELECT()" > 
           <table border=3px solid black;> 
             <tr> 
              <th width="15%" align="center">Area</th> 
              <th width="15%" align="center">Flat/Bungalo</th> 
              <th width="12%" align="center">BHK</th> 
              <th width="12%">Rent</th> 
              <th width="16%">Deposit</th> 
              <th width="10%">SQ Ft</th> 
              <th width="10%">FLoor</th> 
              <th width="10%">Lift</th> 
             </tr> 

              <?php 

               $select="select area,proptype,address,bhk,rent,diposit,sqft,floor,lift 
                 from propertymaster where area='$an' and bhk='$flat' and rentorsale='$rentsale'"; 
               $property=mysql_query($select); 
               while($row=mysql_fetch_assoc($property)) 
               { 
               ?> 
               <tr class="tr1"> 
               <td class="td1"> 
                <?php echo $row['area'];?> 
               </td> 
               <td align="center"> 
                <?php echo $row['proptype'];?> 
               </td> 
               <td> 
                <?php echo $row['bhk'];?> 
               </td> 
               <td> 
                <?php echo $row['rent'];?> 
               </td> 
               <td> 
                <?php echo $row['diposit'];?> 
               </td> 
               <td> 
                <?php echo $row['sqft'];?> 
               </td> 
               <td> 
                <?php echo $row['floor'];?> 
               </td> 
               <td width="20px"> 
                <?php echo $row['lift'];?> 
               </td> 
               </tr> 
              <?php 
             } 
             ?> 
             </table> 
           <table class="closebutton"> 
           <tr class="trclose" align="center"> 
           <td></td> 
           <td width='260px'></td> 
           <td> 
           <a href="home.php?unsetsession=1"> 
             <input type="submit" name="Close" style="width:75" id="Close" value="Close" class="button"></a> 
            </td> 
           </tr>  
           </table> 
          </form> 
     </div>      
     </html> 
    </div> 
    <?php        } ?> 


<?php if(!isset($_SESSION['an']))  { ?> 
    <div Class="mainBlock5" style="width:100%"> 
     <p>testing div</p> </div> 
      <?php  }  ?> 

</div> 
    <div class="col-sm-2 sidenav"> 
     <div class="well"> 
     <p>ADS</p>  <img src="../riteshproject/login1.jpg" width="80" height="50"> 
     </div> 
     <div class="well"> 
     <p>ADS</p> 
     </div> 
    </div> </div> </div> 

<footer class="container-fluid text-center"> 
<p><b><marquee>Designed,Developed and Maintened By Shree Shree 
Property,Kolhapur Mob No 9373002173</b></marquee></p> </footer> 
</body> </html> 

<script> function notSELECT() { 
      var inputControls = document.getElementsByClassName("areaname"); 
      if (inputControls.value== "SELECT")   { 
      alert("Enter Proper search Values"); 

      return false; 
     } 

    return true; } 

</script> 

:これとは別に、私もそれがあるアラートは、それぞれのlable

私の試みであるはず「SELECT」が見つかりoption.whereverすべてのドロップダウンのためにこれを必要とします

条件は私がonsubmit="notSELECT()"

formタグでその関数を書いた を「SELECT」と alert(); を示して、それを確認した場合、私は値が getElementByName を使用し、使用して取得210

ので、plzは警告MSGに

を表示するために私を助けて、このコードでは、私に

+2

が。それは現在の状態だで、良い答えを得ることはほとんどありませんので、あなたの質問を編集して、より良いフォーマットしてください – Dacaspex

+0

主なものは、(私はPHPの関数notSELECT内のJavaScriptを書いたということである) { \t \tするvar inputControls = document.getElementsByClassName(」 areaname "); \t \t \t場合(inputControls.value == "SELECT") \t \t { 警告( "適切な検索値を入力します。"); \t \t \t return false; } を返します。 } それは書き込みですか? –

答えて

0

を助けてください:あなたは「AREANAME」のクラス名を持つすべての要素を選択しよう

function notSELECT() { 
    var inputControls = document.getElementsByClassName("areaname"); 
    if (inputControls.value== "SELECT")   { 
     alert("Enter Proper search Values"); 
     return false; 
    } 
    return true; 
} 

が、私その名前のクラスを見つけることができないようです。おそらくこれは、あなたが望んでいる:

function notSELECT() { 
    var inputControls = document.getElementById("areaname"); 
    if (inputControls.value== "SELECT")   { 
     alert("Enter Proper search Values"); 
     return false; 
    } 
    return true; 
} 

EDIT:あなたの2番目の質問については
(あなたがコメントで述べた)ここのコードです:低品質としてフラグ付け

function notSELECT() { 
    var inputControlsAreaName = document.getElementById("areaname"); 
    var inputControlsFlat = document.getElementById("flat"); 
    if (inputControlsAreaName.value== "SELECT")   { 
     alert("Please select areaname"); 
     return false; 
    } 
    if (inputControlsFlat.value== "SELECT")   { 
     alert("Please select flat"); 
     return false; 
    } 
    return true; 
} 
+0

私はそれが 'getElementsById'の代わりに' getElementById'であるべきだと思います。 –

+0

ok私はdocument.getElementsById()を試しましたが、まだ私は警告を受け取っていません –

+0

素晴らしい答え@Andewその仕事.the残っている唯一のものは、どこのユーザーが値を選択したいのですか?ラベルはどれですか? –

関連する問題