|
AJAX and PHP Part: Forms and JavaScript Limitations
AJAX & JavaScript Limitations
There is also a clear limitation on how you can use JavaScript within the dynamically updated (AJAX generated) content of a page. You can do as we did in our example above in file Listing #B where we had an onClick event that calls a JavaScript function (which is actually defined in the main HTML page file which is Listing #A).
You can also do the following (note the following is an edited version of Listing #B above; it is displayed as dynamic AJAX content on a page). The following changes the "txt1" field element content with an onClick event that uses a standard JavaScript method, referencing the "txt1" field by ID as you notice on the highlighted line below.
<h3>Here is an HTML Form, enter data, click submit X2...</h3>
<Form name="myform">
Type text: <input type="text" size="15" id="txt1" >
<br><br>
<input type="button" value="Press to submit form" onClick="doHttpRequest2();">
<input type="button" value="Change" onClick="document.getElementById ('txt1').value='We-change';">
</Form>
Warning: You cannot do the following, which has a user-defined JavaScript function in the AJAX dynamic content. JavaScript functions defined within dynamic AJAX content simply will not function.
<script language="javascript" type="text/javascript">
function changetxt1() { document.getElementById('txt1').value='We-change'; }
</script>
<h3>Here is an HTML Form, enter data, click submit X2...</h3>
<Form name="myform">
Type text: <input type="text" size="15" id="txt1" >
<br><br>
<input type="button" value="Press to submit form" onClick="doHttpRequest2();">
<input type="button" value="Change" onClick="changetxt1();">
</Form>
Come back soon to read the next article in our series on Ajax and PHP!
| Comments: | ||
| RE: Limits in accessing form elements by name | Greg Burghardt | 01/08/09 11:19 |
| AJAX to run a javascript from a form button | Tom Wilson | 07/02/08 11:24 |
| Sending a form using an AJAX library | Arnold Daniels | 08/11/07 12:16 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly. | ||


