Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

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!


[Page 1]  [Page 2]  


Comments:
RE: Limits in accessing form elements by nameGreg Burghardt01/08/09 11:19
AJAX to run a javascript from a form buttonTom Wilson07/02/08 11:24
Sending a form using an AJAX libraryArnold Daniels08/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.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.