简体   繁体   English

使用onChange提交表单,ajax,php和Mysql.Dropdown列表的值不会发送到php提交页面

[英]Submitting a form using onChange,ajax,php and Mysql.Dropdown list's value is not sent to the php submit page

I have a form which has a drop down list for countries. 我有一个表格,其中有一个国家的下拉列表。

If the user chooses one of the countries (onchange), a new drop down list for cities appears displaying only the cities of this specific country. 如果用户选择其中一个国家/地区(onchange),则会显示城市的新下拉列表,仅显示此特定国家/地区的城市。

<select name = \"countries\" id=\"ListOfCountries\" onchange=\"showCities(this.value)\">

I have implemented that by using php, mysql and ajax. 我已经通过使用php,mysql和ajax实现了它。

The tutorial i have studied and followed is in the following link: 我研究和遵循的教程在以下链接中:

http://www.w3schools.com/php/php_ajax_database.asp http://www.w3schools.com/php/php_ajax_database.asp

The drop down list for cities is displayed automatically on the web page without loading the page again. 城市的下拉列表会自动显示在网页上,而不会再次加载页面。

When the cities box appears, if i do Ctrl-U in order to see the source code of the page, the html code for the drop down list of cities is not in the source code page. 当出现城市框时,如果我执行Ctrl-U以查看页面的源代码,则城市下拉列表的html代码不在源代码页中。

My problem is that when i submit the form, the value of the cities' drop down list is NOT sent to the submit.php file 我的问题是,当我提交表单时,城市下拉列表的值不会发送submit.php文件

index.php 的index.php

 <form action="submit.php" name="my_form" method="post">

submit.php submit.php

 echo $_POST['cities'];

The $_POST['cities']; $ _POST ['cities']; is blank. 是空白的。

That means that in the submit page NO value for cities' drop down list was sent. 这意味着在提交页面中发送了城市下拉列表的NO值。

What am i supposed to do in order to fix that? 为了解决这个问题,我该怎么做?

Thanks, in advance 提前致谢

Add a client side and server side validator . 添加客户端和服务器端验证器。 For example on client side if no cities are selected disable submit button . 例如,在客户端,如果没有选择城市,则禁用提交按钮。 And on server side if isset($_POST['cities']) is false then don't execute any query simply redirect user to same page with error message "Please select cities" 在服务器端,如果isset($_POST['cities'])为false,则不执行任何查询只需将用户重定向到同一页面,并显示错误消息“请选择城市”

It seems like you are not updating the DOM correcly, so the cities parameter is not avaible when you submit the form. 您似乎没有正确更新DOM,因此在提交表单时无法使用cities参数。 If you use jQuery, use jQuery.after() or any similar function to update the DOM. 如果您使用jQuery,请使用jQuery.after()或任何类似的函数来更新DOM。 If not you'll have to create a node with the select and add it into the form. 如果不是,则必须使用select创建节点并将其添加到表单中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 下拉框,使用AJAX和PHP向MYSQL db OnChange插入值 - Dropdown box to insert value to MYSQL db OnChange using AJAX and PHP 从下拉列表中将选定的值分配给PHP变量onchange,而无需按html表单中的“提交”按钮? - Assigning a selected value from a dropdown list to a php variable onchange, without pressing submit button in a html form? PHP onchange = this.form.submit()在下拉菜单中-&gt;第一个值丢失 - PHP onchange=this.form.submit() on dropdown -> First value get lost 如何使用 PHP 中的 AJAX 从数据库动态填充下拉框而不提交表单和页面刷新? - How to fill dropdown box dynamically from database without submitting form and page refresh using AJAX in PHP? 在提交表单之前将下拉列表的选定值传递给 php 变量 - Passing the selected value of a dropdown list to a php variable before submitting the form 将表单提交到PHP页面,而无需使用Submit按钮重新加载 - submitting form to PHP page without reloading using the submit button 使用AJAX将PHP表单提交到MYSQL数据库 - Submit PHP form to MYSQL database using AJAX 在提交表单之前将下拉列表的选定值传递给 php 变量 - Passing the selected value of dropdown list to a php variable before submitting the form 对于下拉列表的onchange,从数据库中获取数据而无需在php中提交表单 - For onchange of the Dropdown list fetch the data from the db with out submitting the form in php 表单未使用 ajax 和 php 提交? - Form is not submitting using ajax and php?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM