I am completely new to the world of Ajax, having just started learning about it a few days ago. Despite my lack of experience, I need to incorporate it into a form that I am creating for my employer.
Unfortunately, I have been facing difficulties in getting multiple functions to work properly. Specifically, I am attempting to update four different sections of a webpage based on a single dropdown selection using the onchange
event. While updating one section works fine, trying to update more than that results in failure. Additionally, even simple actions like displaying an alert message after an Ajax call seem to cause problems. It's as if the functionality breaks down sequentially. Oddly enough, if I mix events such as onchange
and onblur
on the same element, the function executes twice. I will provide the code below to clarify further.
<select name="pType" id="ptype" onchange="dostuff()">
This is the input element...
<script type="text/javascript">
function dostuff(){
ajaxpage('adminincludes/popoptions.php?pID=<?= $sql['pID']; ?>&pType=' + ptype.value,'options');
alert('test');
}
</script>
...and here is an example of the dostuff
function. Please ignore the PHP portion as the issue persists regardless of that part - the PHP component functions correctly.
The remaining code resides in an external file, and I suspect that the problem lies within that script. However, being relatively new to Ajax and not particularly proficient in JavaScript (having only learned what was necessary at any given moment), I find myself struggling to pinpoint the exact cause.
//Remaining code provided
In conclusion, while the code performs without issue with a single call to ajaxpage()
, it fails to execute multiple times within a single event. Even when combining multiple instances within the dostuff()
function, the desired outcome remains elusive.
Any assistance or guidance in resolving this matter would be greatly appreciated, as it has become quite frustrating.
UPDATE: The urgency of this issue has decreased slightly, as I have found a "workaround" by utilizing various events such as mouseover and mouseout on an update link instead. This solution achieves the desired functionality, though it lacks elegance. Nevertheless, I remain intrigued by the underlying reason why the code does not work as expected when called multiple times within a single event?!.