Hi.,
In my page i have a form which has a list box named mediatype which has few values (type1,type2...).
An ajax function is called in the onchange event and the correcponding publication types are displayed in the ajax page which displays below the mediatype listbox.
similarly three more listboxes are displayed when the publication type is changed, using the same ajax function.
all works fine.,
but when i submit the page and retrieve the posted value no value is returned., i get null values for all the fields or listboxes that are generated through ajax.
any help..
below is my complete code.,
thanks.,
regards
vijay -
-
<html>
-
<head>
-
<script type="text/javascript">
-
function createRequestObj()
-
{
-
var xmlHttp = null;
-
if (window.XMLHttpRequest){
-
xmlHttp = new XMLHttpRequest();
-
if (xmlHttp.overrideMimeType) {
-
xmlHttp.overrideMimeType('text/html');
-
}
-
}
-
else
-
{
-
if (window.ActiveXObject){
-
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
-
if (xmlHttp.overrideMimeType) {
-
xmlHttp.overrideMimeType('text/html');
-
}
-
}
-
}
-
return xmlHttp;
-
}
-
-
function ajx1(vari1,vari2)
-
{
-
var d = new Date();
-
var time = d.getTime();
-
-
if(vari1=='media')
-
var url = "ajx1.php?Time="+time;
-
else if(vari1=='pub_type')
-
var url = "ajx2.php?Time="+time;
-
url = url + "&data="+vari2;
-
-
var xmlHttp =createRequestObj();
-
xmlHttp.open("GET",url,true);
-
xmlHttp.onreadystatechange = function()
-
{
-
if(xmlHttp.readyState==4)
-
{
-
if(vari1=='media')
-
document.getElementById("media").innerHTML=xmlHttp.responseText;
-
else if(vari1=='pub_type')
-
{
-
document.getElementById("pub_type_tr").style.display='block';
-
document.getElementById("pub_type").innerHTML=xmlHttp.responseText;
-
}
-
}
-
};
-
xmlHttp.send(null);
-
}
-
</script>
-
</head>
-
<body>
-
<table width="100%">
-
<form action="<?php $_SERVER['PHP_SELF'];?>" method="post" name="form1" id="form1">
-
<tr>
-
<td align="right" valign="top"><strong>Media type</strong></td>
-
<td align="left" valign="top"> </td>
-
<td align="left" valign="top"><select name="mediatype" id="mediatype" onchange="ajx1('media',this.value)">
-
<option value="select" selected>-----select-----</option>
-
<option value="type1">type1</option>
-
<option value="type2">type2</option>
-
</select> </td>
-
</tr>
-
<tr id="media">
-
<td align="right" valign="middle"> </td>
-
<td align="left" valign="middle"> </td>
-
<td align="left" valign="middle"> </td>
-
</tr>
-
<tr id="pub_type_tr" style="display:none;">
-
<td colspan="3" align="left" valign="top"><table width="100%" id="pub_type">
-
<tr>
-
<td align="left" valign="top"> </td>
-
</tr>
-
</table></td>
-
</tr>
-
<tr>
-
<td align="right" valign="top"><strong>Date</strong></td>
-
<td align="left" valign="top"> </td>
-
<td align="left" valign="top"><input type="text" name="date" id="date" /></td>
-
</tr>
-
<tr>
-
<td align="right" valign="top"> </td>
-
<td align="left" valign="top"> </td>
-
<td align="left" valign="top"> </td>
-
</tr>
-
-
<tr>
-
<td align="right" valign="top"> </td>
-
<td align="left" valign="top"> </td>
-
<td align="left" valign="top"><input type="submit" name="submit" id="submit" value="Submit" /></td>
-
</tr>
-
</form>
-
</table>
-
</body>
-
</html>
-
code for ajx1.php -
-
<td align="right" height="50px" valign="middle"><strong>Publication type</strong></td>
-
<td align="left" valign="middle"> </td>
-
<td align="left" valign="middle"><select name="pubtype" id="pubtype" onChange="ajx1('pub_type',this.value);">
-
<option selected="selected" value="select">-----select-----</option>
-
<?php
-
include 'config.php';
-
$meditype=$_GET['data'];
-
$qp=mysql_query("select distinct(publication_type) from media_newspaper order by publication_type asc");
-
while($rp=mysql_fetch_object($qp))
-
echo '<option value="'.$rp->publication_type.'">'.$rp->publication_type.'</option>';
-
?>
-
</select></td>
-
code for ajx2.php -
<?php
-
include 'config.php';
-
$mediatype=$_GET['data'];
-
$qp=mysql_query("select * from media_newspaper where publication_type='".$mediatype."'");
-
while($rp=mysql_fetch_object($qp))
-
{
-
$tmpsizes[]=$rp->size;
-
$tmpcolors[]=$rp->color;
-
$tmpposition[]=$rp->position;
-
}
-
?>
-
<tr>
-
<td width="35%" align="right" valign="top"><strong>Size</strong></td>
-
<td width="6%" align="left" valign="top"> </td>
-
<td width="59%" align="left" valign="top"><select name="size" id="size">
-
<?php
-
foreach($tmpsizes as $key=>$value)
-
echo '<option value="'.$value.'">'.$value.'</option>';
-
?>
-
</select>
-
</td>
-
</tr>
-
<tr>
-
<td align="right" valign="top"> </td>
-
<td align="left" valign="top"> </td>
-
<td align="left" valign="top"> </td>
-
</tr>
-
<tr>
-
<td align="right" valign="top"><strong>Color</strong></td>
-
<td align="left" valign="top"> </td>
-
<td align="left" valign="top"><select name="color" id="color">
-
<?php
-
foreach($tmpcolors as $key=>$value)
-
echo '<option value="'.$value.'">'.$value.'</option>';
-
?>
-
</select>
-
</td>
-
</tr>
-
<tr>
-
<td align="right" valign="top"> </td>
-
<td align="left" valign="top"> </td>
-
<td align="left" valign="top"> </td>
-
</tr>
-
<tr>
-
<td align="right" valign="top"><strong>Position</strong></td>
-
<td align="left" valign="top"> </td>
-
<td align="left" valign="top"><select name="position" id="position">
-
<?php
-
foreach($tmpposition as $key=>$value)
-
echo '<option value="'.$value.'">'.$value.'</option>';
-
?>
-
</select>
-
</td>
-
</tr>
-
9 1268
Hello, can we see a sample page for some more debugging... thanks.
Here, did some changes, try testing this and check if this works. Sorry for so many code changes.
HTML:
ajx1.php: -
<?php
-
include 'config.php';
-
-
$meditype=$_GET['data'];
-
-
$qp=mysql_query("select distinct(publication_type) from media_newspaper order by publication_type asc");
-
-
$response = array();
-
-
while($rp=mysql_fetch_object($qp)){
-
$response[] = $rp->publication_type;
-
}
-
-
echo json_encode( $response );
-
?>
ajx2.php: -
<?php
-
include 'config.php';
-
-
$mediatype=$_GET['data'];
-
-
$qp=mysql_query("select * from media_newspaper where publication_type='".$mediatype."'");
-
-
while($rp=mysql_fetch_object($qp)){
-
$tmpsizes[]=$rp->size;
-
$tmpcolors[]=$rp->color;
-
$tmpposition[]=$rp->position;
-
}
-
-
$response = array(
-
"size" => $tmpsizes,
-
"color" => $tmpcolors,
-
"position" => $tmpposition
-
);
-
-
echo json_encode( $response );
-
?>
hello canabeez.,
working in localhost sorry., unable to give u a sample page.,
i tried your ideas and implemented it in the pages.,
the first function works fine and the posted value is retrieved when i submit the form.
but the second function didnt work properly.,
no results were found.,
i tried by placing some alert functions to examine where the process stops., but unfortunately it doesnt even enter the function., -
-
function drawOthers(_data){
-
alert('here');
-
for(var obj in _data){
-
var sel = document.getElementById(obj);
-
sel.innerHTML = '';
-
for(var i in _data[obj]){
-
var opt = document.createElement('option');
-
opt.value = _data[obj][i];
-
opt.innerHTML = _data[obj][i];
-
sel.appendChild(opt);
-
}
-
}
-
document.getElementById('pub_type_tr').style.display = 'inline';
-
}
-
and even tried by commenting all the other lines but again no results found.. -
-
function drawOthers(_data){alert('here');
-
/* for(var obj in _data){
-
var sel = document.getElementById(obj);
-
sel.innerHTML = '';
-
for(var i in _data[obj]){
-
var opt = document.createElement('option');
-
opt.value = _data[obj][i];
-
opt.innerHTML = _data[obj][i];
-
sel.appendChild(opt);
-
}
-
}
-
document.getElementById('pub_type_tr').style.display = 'inline';
-
*/
-
}
-
and checked for the error's in ajx2.php page by directly writing the url http://localhost/project2/ajx2.php?data=paper1
where paper1 is the value sent from the onchange event called in "pubtype(listbox name)" which is produced from the first ajax function.
it displays the result as
{"size":["3"],"color":["black&white"],"position":["Run on page"]}
thanks
Are you getting any errors?
Please also check that the response from the second function ("drawOthers()") does not enter the first one ("drawMedia()").
checked., the result is good., when i added the code -
alert(xmlHttp.responseText);
-
it shows the same result perfectly as
{"size":["3"],"color":["black&white"],"position":["Run on page"]}
Try alerting the vari1 variable inside the onreadystatechange() function -
xmlHttp.onreadystatechange = function()
-
{
-
if(xmlHttp.readyState==4)
-
{
-
alert( vari1 );
-
}
-
};
result is "pub_type".
i think there might be some error's inside the second function since the javascript doesnt even enter it..
Try adding -
<input type="button" value="Test" onclick="drawOthers({"size":["3"],"color":["black&white"],"position":["Run on page"]});" />
to your html and test the function itself, see if there are any JavaScript errors.
hey it works perfectly man., all the list boxes are filled with their values.,
but when the function is called through the onchange event of the generated listbox nothing happens..
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jacob |
last post by:
I have a page Add_data.asp which accepts a number of user-entered variables
and then inserts them into a database. I have another page, Loc_tree.asp
which when accessed, returns a tree of...
|
by: Ron Vecchi |
last post by:
I know the math I need to perform on width and height to keep an aspect
ratio but where and how would I implement keeping a set aspect ratio on a
form when a user resizes it. Override OnResize?...
|
by: tom |
last post by:
Hi Experts,
I want to pass the selectedDate value from my calender
form to another web form or a web user control. Could you
please show me how to do this?
Thanks in advance.
|
by: testuser |
last post by:
works fine in FF, not in IE
form
<form action = go.php method = get> <input type='checkbox' name='id' value='1'> <input type='checkbox' name='id' value='2'> <input type='checkbox' name='id'...
|
by: vunet.us |
last post by:
Hi all,
I am converting my app to AJAX-based. I have a form that submits some
data including images. When I use AJAX XmlHttpRequest I am unable to
submit the form with...
|
by: registerhere |
last post by:
Hi,
I was working with acrojavascript when i came acroos it.
I have a pdf form. A global variable t=1 is initialized. Just before the form is closed, it calls a function dat increments its...
|
by: jd2007 |
last post by:
Why the Ajax code below in ajax.js is causing my form not to work ?
ajax.js:
var a=0;
var b=0;
var c=0;
var d=0;
var e=0;
var f=0;
|
by: nicky77 |
last post by:
This is a long shot, but I have no idea why my navbar is being temperamental in IE6. Everything looks ok on page load, but when you fill out the online form and click Submit, the navbar either...
|
by: Rob |
last post by:
I have a control (Button) on a Parent form which opens a Windows form... all
I want to do is pass a value from the child form back to the parent... it
should be so simple... i.e....
|
by: vikas251074 |
last post by:
I am storing value by the following
<td>Name of Person</td>
<td><input type="text" width="100px" name="vname" value=<%=vname%>>
</td>
When I enter 'Vikas Kumar' and press enter key only...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |