将自动填充的数据传递到另一个PHP页面

时间:2014-12-05 08:11:04

标签: javascript php

如何将此表单中的自动填充数据传递给budget.php?我一直在尝试使用POST,但它无法通过自动填充的内容。它只传递用户在此表单中键入的内容参考编号距离但不会在下拉列表选择中填充的内容

                        <form action="budget.php" method="post" enctype="multipart/form-data" name="budget" onsubmit="return validateForm()" align="center">

                            <style>
                            form input { padding: 3px; }
                            </style>
                                <div align="center">
                                    <p><u><strong>Kindly enter the Trip ID.</u></strong></p>
                                    <table border=1 cellpadding=2 rows=1>
                                    <form name="budget">
                                    Ref No:<br />
                                    <input name="refno" type="text" class="ed" /><br />
                                     Distance:<br />
                                    <input name="distance" type="text" id="distance" class="ed" onkeypress="return isNumberKey(event)" /><br />
                                     Fuel Cost/Litre<br/>
                                    <input name="fuelcostperl" type="text" id="fuelcostperl" class="ed" onkeypress="return isNumberKey(event)" /><br />
                                    <br>
                                    <br>
                                    <u><strong><align = "left"/>Please Enter the Trip No:/ID to Calculate the budget</strong>
                                    <tr><td>Trip No:</label></td><td><input type='text' name='req_id' id="req_id" size=20 onchange="updateBudget()">
                                    <td>Drop Date:</td><td><input type='text' id='dropdate' disabled="disabled"/></td></tr>
                                    <tr><td>Initials:</td><td><input type='text' id='init' disabled="disabled"/></td>
                                    <div id="GetInformation">
                                    <td>Destination:</td><td><input type='text' id='destination' disabled="disabled"/></td></tr>
                                    <tr><td>First Name:</td><td><input type='text' id='fname' disabled="disabled "/>
                                    <td>Number Of Persons:</td><td><input type='text' id='no_persons' disabled="disabled"/></td></tr>
                                    <tr><td>Othernames:</td><td><input type='text' id='othernames' disabled="disabled"/>
                                    <td>Vote:</td><td><input type='text' id='vote'/disabled="disabled"></td></tr>
                                    <tr><td>Email Address:</td><td><input type='text' id='email' disabled="disabled"/>
                                    <td>Trip Purpose:</td><td><input textarea id='tripreason' disabled="disabled"/></td></tr>
                                    <tr><td>Trip Date:</td><td><input type='text' id='tripdate'disabled="disabled"/>
                                    </tr>
                                    <tr>
                                    </tr>
                                    <tr></tr>
                                    <tr></tr>
                                    <tr></tr>
                                    <tr></tr>

                            <script>
                            var ajax = getHTTPObject();

                                    function getHTTPObject()
                                    {
                                        var xmlhttp;
                                        if (window.XMLHttpRequest) {
                                          // code for IE7+, Firefox, Chrome, Opera, Safari
                                          xmlhttp=new XMLHttpRequest();
                                        } else if (window.ActiveXObject) {
                                          // code for IE6, IE5
                                          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                                        } else {
                                          //alert("Your browser does not support XMLHTTP!");
                                        }
                                        return xmlhttp;
                                    }

                                    function updateBudget()
                                    {
                                        if (ajax)
                                        {
                                            var reqValue = document.getElementById("req_id").value;
                                            if(reqValue)
                                            {
                                                var url = "populatebudget.php";
                                                var param = "?req_id=" + escape(reqValue);

                                                ajax.open("GET", url + param, true);
                                                ajax.onreadystatechange = handleAjax;
                                                ajax.send(null);
                                            }
                                        }
                                    }


                                    function handleAjax()
                                    {
                                        if (ajax.readyState == 4)
                                        {
                                            budgetarr = ajax.responseText.split(",");

                                            var init = document.getElementById('init');
                                            var fname = document.getElementById('fname');
                                            var othernames = document.getElementById('othernames');
                                            var email = document.getElementById('email');
                                            var tripdate = document.getElementById('tripdate');
                                            var dropdate = document.getElementById('dropdate');
                                            var destination = document.getElementById('destination');
                                            var no_persons = document.getElementById('no_persons');
                                            var vote = document.getElementById('vote');
                                            var tripreason = document.getElementById('tripreason');

                                            init.value = budgetarr[0];
                                            fname.value = budgetarr[1];
                                            othernames.value = budgetarr[2];
                                            email.value = budgetarr[3];
                                            tripdate.value = budgetarr[4];
                                            dropdate.value = budgetarr[5];
                                            destination.value = budgetarr[6];
                                            no_persons.value = budgetarr[7];
                                            vote.value = budgetarr[8];
                                            tripreason.value = budgetarr[9];

                                        }
                                    }
                            </script>
                                    </table>
                                    <script type="text/javascript">
                                        function showUser(str){
                                            if (str == "") {
                                                document.getElementById("txtHint").innerHTML = "";
                                                return;
                                            }
                                            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 (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                                                    document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
                                                }
                                            }
                                            xmlhttp.open("GET", "getdriver.php?q=" + str, true);
                                            xmlhttp.send();
                                        }
                                    </script>

0 个答案:

没有答案