PHPBuilder - AJAX and PHP Part: Forms and JavaScript Limitations Page 2 Page 2



RSS Twitter
Articles

AJAX and PHP Part: Forms and JavaScript Limitations Page 2 - Page 2

by: J.D.Campbell
|
January 23, 2009

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!



« Previous Page
1

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
J.D.Campbell

Comment:



Comment:

(Maximum characters: 1200). You have characters left.