[英]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.