View Full Version : Javascript does not work upon AJAX call

04-07-2011, 06:35 PM
1) Script Title: Javascript does not work upon AJAX call
2)Script URL(DD):http://www.dynamicdrive.com/forums/showthread.php?t=13003
3) Describe problem:
I have a page which does an AJAX call and loads an entire page. The page that gets loaded has some Javascript. The javascript works on page by itself when loaded, but when its gets loaded by AJAX, the Javascript does not work. I dont know what I am missing.

The code of the loaded page is

<script type="text/javascript">
function showfield(name){
else document.getElementById('div1').style.display="none";

function hidefield() {


<body onload="hidefield()">
<form action = "test2.php" method = "post">

Please enter a name for the App <input type = "text" name = "name">

<table border = "1"><tr><th>Choose a Label</th><th>Choose an element</th></tr>

<tr><td><input type = "text" name = "label1" /></td> <td>

<select name = "elementtype1" id="elementtype1" onchange="showfield(this.options[this.selectedIndex].value)">

<option value = 'select'> Select </option>

<option value='txtbox'>Text Box</option>

<option value='lstbox'>List Box</option>

<option value='chkbox'>Check Box</option>

<option value='radio'>Radio Button</option>

</select></td><td><div id="div1">Enter Listbox options: <input type="text" name="whatever1" /></div></td></tr>


<input type = "submit" value = "Submit">




The code of the loading(AJAX) page is


<script src="ajax.js" type="text/javascript"></script>
<script src="responseHTML.js" type="text/javascript"></script>

<div id="storage" style="display:none;">

<div id="displayed">

<FORM name="ajax" method="POST" action="">

<INPUT type="BUTTON" value="Get the Panel" ONCLICK="loadWholePage('appcreator.php')">