":"用于匹配

时间:2017-07-04 10:15:41

标签: php

我正在尝试做这样的事情。如果大学选择不在下拉列表中,则用户选择"其他"现在,当他选择其他人时,他会移动到文本框并输入大学名称。

代码看起来像这样

                        <?php
                        if(isset($_POST['work_exp'])){
                        $inst_name = $_POST['inst_name'];
                        $inst_name2 = $_POST['inst_name2'];

                        if($inst_name =='Other')
                        {
                            $inst_name2:$inst_name;
                            echo $inst_name;
                        }

                            }
                        ?>

现在我遇到的挑战是它像这样返回错误

Parse error: syntax error, unexpected ':' in C:\xampp\htdocs\seekweb\brWeb.php on line 229

有什么想法吗?代码在这里工作得非常好

<!doctype html>
<html>
<head></head>
<title>test for dropdown</title>
<body>
<form name="school_form" id="school_form" method="post" action="test_form.php" />
<h1>Drop down Box test</h1>
School name :<select name="school" id="school" />
         <option selected="selected">Please Select School</option>
         <option>Catania School of Medicine</option>
         <option>J.M Hart University</option>
        <option>Beulah College of Business</option>
        <option>Crownay University</option>
        <option>Other</option>
        </select></br></p>
If Other, Please Enter Institution name : <input type="text" name="otherschool" id="otherschool" /></br></p>
<input type="submit" name="submit" value="Add School" />
</form>
</body>
</html>

<?php

if(isset($_POST['submit'])){
    $school = $_POST['school'];
    $otherschool = $_POST['otherschool'];

    if($school =="Other")
    {
        $otherschool:$school;
        echo $school;
    }

}

?>

1 个答案:

答案 0 :(得分:-1)

  

这是您的工作代码!!

<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>


<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">

<!-- Modal -->


    <div class="form-group">

     <select name="school" id='type'>
     <option selected="selected" disabled="disabled">Please Select School</option>
     <option>Catania School of Medicine</option>
     <option>J.M Hart University</option>
     <option>Beulah College of Business</option>
     <option>Crownay University</option>
     <option value='Other'>Other</option>
     </select>


    <div id="myModal" class="modal fade" role="dialog">
      <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Please Enter Institution name : </h4>
          </div>
          <div class="modal-body">
            <input type="text" class="form-control" id="name" name="otherschool" placeholder="Enter Name">
          </div>
          <div class="modal-footer">
            <button type="button" name="submit" class="btn btn-primary" data-dismiss="modal">Save</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
        <!-- Modal content-->

      </div>
    </div>

   </div>


<button type="submit" name="submit" class="btn btn-primary" data-dismiss="modal">Sumbit</button>
</form>


<?php

if(isset($_POST['submit'])){
    $school = $_POST['school'];
    $otherschool = $_POST['otherschool'];

    if($school === "Other")
    {
        echo $otherschool;
        // insert code of other

    }
    else{


      echo $school;

    }

}

?>





<script type="text/javascript">

  $("#type").on("change", function () {        
      $modal = $('#myModal');
      if($(this).val() === 'Other'){
        $modal.modal('show');
    }
 });

</script>
  

下载工作文件并在您的服务器中运行:https://ufile.io/taj8x

  $("#type").on("change", function () {        
      $modal = $('#myModal');
      if($(this).val() === 'Other'){
        $modal.modal('show');
    }
 });
<script src="https://code.jquery.com/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>


<form method="post" action="<?php echo $_SERVER["PHP_SELF"];?>">

<!-- Modal -->

 
    <div class="form-group">
      
     <select name="school" id='type'>
     <option selected="selected" disabled="disabled">Please Select School</option>
     <option>Catania School of Medicine</option>
     <option>J.M Hart University</option>
     <option>Beulah College of Business</option>
     <option>Crownay University</option>
     <option value='Other'>Other</option>
     </select>


    <div id="myModal" class="modal fade" role="dialog">
      <div class="modal-dialog">

        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Please Enter Institution name : </h4>
          </div>
          <div class="modal-body">
            <input type="text" class="form-control" id="name" name="otherschool" placeholder="Enter Name">
          </div>
          <div class="modal-footer">
            <button type="button" name="submit" class="btn btn-primary" data-dismiss="modal">Save</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
        <!-- Modal content-->

      </div>
    </div>

   </div>


<button type="submit" name="submit" class="btn btn-primary" data-dismiss="modal">Sumbit</button>
</form>


<?php

if(isset($_POST['submit'])){
    $school = $_POST['school'];
    $otherschool = $_POST['otherschool'];

    if($school === "Other")
    {
        echo $otherschool;
        // insert code of other

    }
    else{


      echo $school;

    }

}

?>