2016-12-21 76 views
1

我有一個接觸腳本如下:傳遞價值主要形式

<?php 
    Session_start(); 
    if (!isset($_SESSION['username'])){ 
    header("Location:../index.php"); 
    } 
    ?> 
    <!DOCTYPE html> 
    <html lang="en"> 
    <head> 
    <meta charset="UTF-8"> 
    <title>Test Modal</title> 
    <link rel="stylesheet" href="../css/style.css"> 
    <link href="../libraries/css/bootstrap.min.css" rel="stylesheet" media="screen"> 
    <link href="../libraries/css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen"> 
    <link rel="stylesheet" href="../libraries/css/jquery-ui.css"> 
    <script src="../libraries/js/jquery-1.10.2.js"></script> 
    <script src="../libraries/js/jquery-ui.js"></script> 
    <script type="text/javascript" src="../libraries/date/jquery/jquery-1.8.3.min.js" charset="UTF-8"></script> 
    <script type="text/javascript" src="../libraries/date/bootstrap/js/bootstrap.min.js"></script> 
    <script> 
     // Get Organization ID 
     function getOrganizationID(str) { 
      if (str == "") { 
       document.getElementById("txtHint").innerHTML = ""; 
       return; 
      } else { 
       if (window.XMLHttpRequest) { 
        // code for IE7+, Firefox, Chrome, Opera, Safari 
        xmlhttp = new XMLHttpRequest(); 
       } else { 
        // code for IE6, IE5 
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
       } 
       xmlhttp.onreadystatechange = function() { 
        if (this.readyState == 4 && this.status == 200) { 

         document.getElementById("txtHint").innerHTML = this.responseText; 
        } 
       }; 
       xmlhttp.open("GET","getorganizationid.php?q="+str,true); 
       xmlhttp.send(); 
      } 
     } 
     // Auto Complete for Organization field 
     $(function() { 
      $("#skills").autocomplete({ 
       source: '../libraries/organization/search.php' 
      }); 
     }); 
    </script> 
    </head> 
    <script type="text/javascript"> 
     // 
     function chName(value) { 
      var val_fname = document.getElementById('fname').value; 
      var val_lname = document.getElementById('lname').value; 
      var val_fullname = val_fname + ' ' + val_lname; 
      document.getElementById('org').value = val_fullname; 
     } 
     // Get the modal 
    var modal = document.getElementById('myModal'); 

    // Get the button that opens the modal 
    var btn = document.getElementById("myBtn"); 

    // Get the <span> element that closes the modal 
    var span = document.getElementsByClassName("close")[0]; 

    // When the user clicks on the button, open the modal 
    btn.onclick = function() { 
     modal.style.display = "block"; 
    } 

    // When the user clicks on <span> (x), close the modal 
    span.onclick = function() { 
     modal.style.display = "none"; 
    } 

    // When the user clicks anywhere outside of the modal, close it 
    window.onclick = function(event) { 
     if (event.target == modal) { 
      modal.style.display = "none"; 
     } 
    } 
    </script> 
    <div id="main"> 
    <form name="create" id="create" method="post" action="do_create.php"> 
     <table style="width:100%;font-weight:bold;"> 
      <tr> 
       <td>First Name</td> 
       <td><input id="fname" name="fname" type="text" required>*</td> 
       <td>Last Name</td> 
       <td><input id="lname" name="lname" type="text" onblur="chName(this.value)" required>*</td> 
      </tr> 
      <tr> 
       <td>Phone</td> 
       <td><input name="phone" type="text" required>*</td> 
       <td>Email</td> 
       <td><input name="email" type="text" required>*</td> 
      </tr> 

      <tr> 
       <td>Mobile Phone</td> 
       <td><input name="mobile" type="text"></td> 
       <td>Organization</td> 
       <td> 
        <input id="skills" type="text" name="skills" value="" onblur="getOrganizationID(this.value);return false;"> 
        <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">+</button> 
        <div id="txtHint" style="width:1px;height:1px;"> 
         <input id="organization_id" name="organization" type="hidden" readonly> 
        </div> 
        <input id="org1" type="hidden" name="ocname" value="<?php echo $hash;?>"> 

       </td> 
      </tr> 
     </table> 
    </form> 
    </div> 


    <!-- The Modal --> 
    <div id="myModal" class="modal"> 
     <!-- Modal content --> 
    <div class="modal-content"> 
    <script type="text/javascript"> 
     function chOrg(value) { 
     var val_oname = document.getElementById('oname').value; 
      document.getElementById('skills').value = val_oname; 
     } 
    </script> 
      <form name="addorganization" id="addorganization" method="post" action="add_organization.php" target="myIframe" onsubmit="chOrg(this.value)"> 
      <div id="headsum"> 
       <strong>Create Organization</strong> 
       <input style="float:right;" name="add_organization" type="submit" value="SAVE"> 
      </div> 
       <table style="width:100%;font-weight:bold;text-align:left;"> 
        <tr> 
         <td>Organization Name</td> 
         <td><input name="oname" type="text" required>*</td> 
         <td>Contact Name</td> 
         <td><input id="org" type="text" name="org" value="" readonly>* 
         <input id="org1" type="hidden" name="ocname" value="<?php echo $hash;?>"></td> 
        </tr> 
        <tr> 
         <td>Phone</td> 
         <td><input name="ophone" type="text" required>*</td> 
         <td>Email</td> 
         <td><input name="oemail" type="text" required>*</td> 
        </tr> 
       </table> 
      </form> 
      <iframe style="display:none;" src="" name="myIframe" id="myIframe"> 
      </iframe> 
    </div> 
    </div> 

當我點擊按鈕旁邊的組織申請,將出現一個彈出(模式)來添加一個組織。 表單上的組織聯繫人姓名將自動填入填寫主表單的名稱。

我想問的是: 組織形式存儲後,組織名稱和主窗體上的散列會自動填入從早期組織形式保存的名稱和散列,因爲我已嘗試未成功

+0

忘記關閉body和html標記 – madalinivascu

+0

@madalinivascu:沒有body和html標記,但無論如何,感謝提醒。 – Gumilar

+0

並且我還發現我缺少一個id(id =「oname」)。 :) 但是,仍然,我需要清理這個腳本,因爲我真的是編程初學者 – Gumilar

回答

0

您好以主窗體中的一個隱藏字段。所以在提交表單後將該值傳遞給隱藏字段。

希望它有幫助!