我需要将数据传递给自己以及html中的action属性中的另一个表单

时间:2016-01-23 03:19:10

标签: php html

我有一个表单,其中有两个组合框,一个是category,另一个是city。根据我从category中选择的内容,我需要转到不同的页面,我完成了如下所示的任务。

例如:如果我在Cars中选择category,我需要转到Cars.html。如果我选择Motorbikes & Scooters,我需要转到Motorbikes&Scooters.html

<form action="<?php $_SERVER["PHP_SELF"]; ?>" method="post" name="myform1">
    <tr>
        <td>
            <label name="category">Category</label>
        </td>
        <td>
            <select id="place" name="Category">
                <option value="select">Please select a Category</option>
                <option value="Cars">Cars</option>
                <option value="Motorbikes & Scooters">Motorbikes and Scooters</option>
                <option value="Three Wheelers">Three Wheelers</option>
                <option value="Vans & Busses">Vans and Busses</option>
                <option value="Heavy-Duty vehicles">Heavy-Duty vehicles</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            <label name="City">City</label>
        </td>
        <td>
            <input type="text" id="textbox1" name="city">
        </td>
        <td>
</form>
<script>
document.getElementById('goTo').onclick = function(e){
    e.preventDefault();
    var yourPath = "",
    yourPage = document.getElementById('place').value;
    extension = '.html';
    window.location = yourPath + yourPage + extension;
}
</script>

我的问题是在此之后,我需要将选定的conditioncity传递给Cars.htmlMotorbikes&Scooters.html等页面(根据组合框中选择的内容)。我怎么能这样做?

1 个答案:

答案 0 :(得分:0)

我真的只知道如何做jQuery,对不起。无论如何,这是我的建议。

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<form action="" method="post" id="myform1">
<table>
    <tr>
        <td>
            <label name="category">Category</label>
        </td>
        <td>
            <select id="place" name="Category">
                <option value="select">Please select a Category</option>
                <option value="Cars">Cars</option>
                <option value="Motorbikes & Scooters">Motorbikes and Scooters</option>
                <option value="Three Wheelers">Three Wheelers</option>
                <option value="Vans & Busses">Vans and Busses</option>
                <option value="Heavy-Duty vehicles">Heavy-Duty vehicles</option>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            <label name="City">City</label>
        </td>
        <td>
            <input type="text" id="textbox1" name="city">
        </td>
        <td>
        <input type="submit" name="goTo" value="GO" />
        </td>
    </tr>
</table>
</form>
<script>
$(document).ready(function() {
    $("#myform1").submit(function(e) {
        var page = $("#place").val().replace(/[^a-zA-Z0-9\-\_]/g, "");
        var city = $("input[name=city]").val();
        var url = '/' + page + '.html?city=' + encodeURIComponent(city);
        window.location = url; 
        console.log(url);
        e.preventDefault();
    });
});
</script>