![]() |
Dynamically add select boxes based on selection
Hello guys,
I have created an interface through which you can add fields and their respective options, the structure is below: Code:
CREATE TABLE fields (Here is the ajax php code: Code:
if (isset($_POST['col']) && isset($_POST['wval']))Code:
<div class="blockrow" id="zfieldblock">Code:
<script type="text/javascript">Thank you! |
I forgot to mention, that this is a vBulletin plugin (hence the {vb:raw varname} instead of $varname), but it should work the same
|
Just realized that the ajax php code is not correct, it should first get the assigned field id of the selected option.
|
I have updated the code in the first post with what I have now but it still doesn't work. Please I really need this, I am willing to donate 30$ to anyone who can help me get this working.
|
One important thing, right from the start
You should get used to using .encodeURIComponent() to ensure proper URI conform encoding of the parameter string. Maybe this is the solution, maybe not :-) Second, and even more important: There was an error in this line. The trailing ' quote has to be omitted Code:
var data_send = 'col='+col+'&wval='+encodeURIComponent(wval);Code:
var request = new XMLHttpRequest();And finally: The onreadystatechange assignment should be after .open() but before .send(). Otherwise it could be possible that certain state changes will not trigger the event handler. Code:
request.open("POST", php_file, true) |
Quote:
|
Either it's time to start debugging or you need to provide us with more information, preferrably in the form of a testable URL.
Hints for debugging: What browser do you use? Firefox: Intall the Firebug plug-in Chrome, IE, Opera: Use the built-in developer tools Safari: Don't know :-) By pressing F12 you'll see the developer tools, where you can observe the script (on the Scripts tab) and the Ajax requests (on the Net tab). You'll be able to see, which information is sent and received and you'll get a general status of your application. |
One more thing:
You are using the variable "preid" everywhere in your code, but it doesn't seem to be defined or set anywhere. What is it? |
Quote:
Quote:
|
Ok, I tested it with firebug and no ajax requests is being made.
|
Did you try to go into full debug mode? Step-by-step execution? Watch expressions? Somehow you need to track down the problem, because the Ajax code itself seems to be quite okay. If you don't give us access to a live URL (maybe even a reduced version) we cannot help you with that.
|
Quote:
|
I tried putting window.alert('test'); into ajaxReq, but upon option change, no message appears.
|
It's really hard to tell where the problem is without access to the application....
Nevertheless, you can activate full debug mode by adding a breakpoint to a line of code that you expect to be executed during your test. Once you start another action or refresh the page the program flow will eventually reach that line and stop. From that point forward you can step through your code (using F10 for step-over and F11 for step-into), observe variables on the "Watch" tab, see messages and/or errors on the Console and net activity on the "Net" tab. Btw, you set a breakpoint in almost every available developer tool by clicking on the line number in the script view. With a right mouse click you can turn the breakpoint into a conditional breakpoint, so you can state a condition under which the breakpoint will stop the program at the current line. |
As an alternative to the above (if you are not comfortable with the Firebug debugging tools) you can add the Web Developer plugin to your installation of Firefox:
https://addons.mozilla.org/en-US/fir...web-developer/ This will give you (among many other useful things) three little circles in your plugin bar at the top right of your browser and when a page loads those circles will turn into green check marks or red X's to indicate whether or not there are javascript or CSS problems with the page being viewed. When javascript errors occur in the page (as in your case) and you click on those three icons it will open the error log and give you a javascript line number and a description of the error to point out exactly where things went wrong. If you won't publish a sample page for us to debug then at least having this information would speed up your debugging process significantly... |
| All times are GMT +1. The time now is 10:46 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.