开发者

using the selected value of a drop down before form submission

i am using a dropdown in php which asks for user_category before creating the user. Upon selection of the category further te开发者_开发问答xt boxes are to be created dynamically depending upon the selection. I know how to get the selected value from $_POST but here i need it befor form submission.Pls help


You would need to use js. Either:

document.getElementById('elementName').value

or

document.formName.elementName.value

or

use jQuery.

Than if you need a response from a php script before submission you would need to use ajax.


You cannot do that ONLY with PHP. PHP is a server-side language, so once you request the page and the PHP interpreter on the server interpreted it and served you the HTML, it does not know anything about what happens to the client. So PHP cannot know if the client changed selection.

What you can do is use JavaScript to do that.

You have 2 options:

1) have the text boxes values that you want to show hard-coded in Javascript for all the cases

2) query a PHP file asynchronously using AJAX so that it will return only the needed values.


You can not get them in php before submission; you may also consider something like simple html dom. Or you can get them with javascript also with something like document.getElementById


you can make this in steps like this: so after the user clicks the submit button right after the dropdown. now you have users choice in the $_POST and you can display the appropriate form. or you do it with js, like nico sad.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜