我试图在我的索引页面上保存表单的输入值,并使用JavaScript将它们带到cookie中的预订页面,但它不起作用。
index.html的表格是:
<form id="check-book" name="check-book" method="post" action="/book.html" onsubmit="return storeValues(this);">
<fieldset>
<label for="field_date_in">Дата заезда:</label>
<input type="text" id="field_date_in" size="8" readonly="readonly" name="sender_checkin"/>
<label for="field_date_out">Дата выезда:</label>
<input type="text" id="field_date_out" size="8" readonly="readonly" name="sender_checkout"/>
<input type="submit" name="send_message" value="Забронировать!">
</fieldset>
</form>
我需要携带到预订页面表单:
<form id="booking-form" name="contact-form" action="send-mail.php" method="POST">
<fieldset>
<legend>Контактная Информация</legend>
<label for="field_name">Имя:</label>
<input type="text" id="field_name" name="sender_name" placeholder="Введите Ваше Имя" autofocus/>
<label for="field_email">E-mail:</label>
<input type="text" id="field_email" pattern="[a-zA-Z]{3,}@[a-zA-Z]{3,}[.]{1}[a-zA-Z]{2,}" title="Пожалуйста введите e-mail" name="sender_email" placeholder="Введите Ваш e-mail">
<label for="field_phone">Номер телефона:</label>
<input type="text" id="field_phone" name="sender_phone" placeholder="Введите Ваш Номер Телефона" >
</fieldset>
<fieldset>
<legend>Информаци о бронировании</legend>
<label for="room_selector">Выберите номер:</label><select name="room_selector" id="room_selector">
<option value="eco_twin">Эконом (Две кровати)</option>
<option value="std_twin">Стандарт (Две кровати)</option>
<option value="std_double">Стандарт (Двойная кровать)</option>
<option value="attic_twin">Эконом Мансарда (Две кровати)</option>
<option value="attic_double">Эконом Мансарда (Двойная кровать)</option>
<option value="lux_twin">Люкс (Две кровати)</option>
<option value="lux_double">Люкс (Двойная кровать)</option>
<option value="lux_wed">Люкс Свадебный</option>
<option value="lux_lux">Суперлюкс</option>
</select>
<label for="field_date_in">Дата заезда:</label>
<input type="text" id="field_date_in" size="8" readonly="readonly" name="sender_checkin"/>
<label for="field_date_out">Дата выезда:</label>
<input type="text" id="field_date_out" size="8" readonly="readonly" name="sender_checkout"/>
<label for="field_guests">Количество гостей:</label>
<input type="number" step="1" value="1" min="1" max="100" id="field_guests" name="sender_guests" />
<label for="field_message">Сообщение:</label>
<textarea id="field_message" name="sender_message" rows="5" cols="50"> </textarea><br>
</fieldset>
<fieldset>
<input type="submit" name="send_message" value="Отправить">
</fieldset>
</form>
我试过的JavaScript是:
<script type="text/javascript">
// Original JavaScript code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.
var today = new Date();
var expiry = new Date(today.getTime() + 30 * 24 * 3600 * 1000); // plus 30 days
function setCookie(name, value)
{
document.cookie=name + "=" + escape(value) + "; path=/; expires=" + expiry.toGMTString();
}
</script>
和
<script type="text/javascript">
function storeValues(form)
{
setCookie("field_date_in", form.field_date_in.value);
setCookie("field_date_out", form.field_date_out.value);
return true;
}
</script>
现在,如何使用存储的Cookie将index.html表单的值上传到book.html? (假设它们被存储)。我对JavaScript非常陌生,对于我而言,我只是在浏览器滞后时用咖啡或干净的东西吃。