0
<script language = "javascript">
      var XMLHttpRequestObject = false;

      if (window.XMLHttpRequest) {
        XMLHttpRequestObject = new XMLHttpRequest();
      } else if (window.ActiveXObject) {
        XMLHttpRequestObject = new
          ActiveXObject("Microsoft.XMLHTTP");
      }

      function getData(dataSource, divID)
      {
        if(XMLHttpRequestObject) {
          var obj = document.getElementById(divID);
          XMLHttpRequestObject.open("GET", dataSource);

          XMLHttpRequestObject.onreadystatechange = function()
          {
             if (XMLHttpRequestObject.readyState == 4 &&
               XMLHttpRequestObject.status == 200) {
                 obj.innerHTML =
                   XMLHttpRequestObject.responseText;
             }
           }

           XMLHttpRequestObject.send(null);
        }
      }
    </script>

Here I call the ajax fuction on post.php :

<tr>
    <td colspan="2" width="250">Choose Subject: <select onchange="getData('post2.php?data='+this.value,
          '[B]mydiv[/B]')" style="width:250px; height:25px; margin-left:5px" name="sub">
	<?php
				include('db.php');
				$queryn=mysql_query("SELECT * FROM  `subjects`");
				echo "<option value=none>=========Select=========</option>";
				while($rown=mysql_fetch_row($queryn))
				
				{
				 echo "<option value=$rown[0]>$rown[1]</option>";
				}
				?> 
                </select></td>
  </tr

>

Here is the blank div where fetched data will be appeared

<tr>
    <td colspan="2" width="400"><div id="fake" style="float:left"> Choose Mother Topic: </div> <div id="[B]mydiv[/B]" style="float:left"> </div>
    </td>
</tr>

And here is the post2.php for

<?php
$sub=$_GET['data'];
include('db.php');
$run=mysql_query("SELECT * from mother_topics where s_id='$sub'");
echo "<select style=width:400px; height:25px; margin-left:5px name=mt>";
while($rows=mysql_fetch_row($run))
				{
				 echo "<option value=$rows[0]>$rows[2]</option>";
				}
echo "</select>";
?>

It works fine and as soon as I change the subject, a dropdown menu appears on mydiv.Pretty fine but when I'm submitting this form and trying to retrieve the value of select name=mt with $var=$_POST; on post.php its cant receive anything!! I need to find a way...please help.

If you still didnt get what Im talking about then go to techysafi.co.cc/login.php and use df and sdf as username and password(dummy), after login go to techysafi.co.cc/post.php .
Thanks

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by TechySafi
0

I have not understood your problem exactly i guess,and your sample site doesn't allow me to login as per your user name and password,i don't know why so.


What i am getting in your problem is like this,
1) You make a drop down dynamically through Ajax and psot2.php on change of the values of your drop down name="sub"

2) But when name="mt" is created,and a value is selected from this second drop down,you want to fire post event on any button or something and want to submit this drop down's selected value to a certain page.


So the solution to this would be here

<tr>
<td colspan="2" width="400"><div id="fake" style="float:left"> Choose Mother Topic: </div> <div id="mydiv" style="float:left"> </div>
</td>
</tr>

The above code that you have written may not be inside your form tag,so what happens is when you create a dropdown dynamically,the dropdown gets created but not inside the form tag,so a post method will not give you that value.

And secondarily please provide an 'Id' attribute to both of the drop downs,because sometimes this also causes the problem,as name attribute sometimes doesn't work as expected.

:)
Hope it helps you...

Edited by Akash Saikia: Little information

0

Yeah, your points are right. But the problem is I can't retrieve the value from newly born drop-down. I guess Im creating that dropdown by echoing from another page, that is causing this problem. Could you suggest me any other way that can perform what I want to do...?

<form action="post.php" method="post">
    <td><textarea class="big" name="topicedit" cols="" rows=""></textarea></td>
  </tr>
  <tr>
    <td>Details:</td>
    <td><textarea class="big2" name="details" cols="" rows=""></textarea></td>
  </tr>
  <tr>
    <td colspan="2" width="250">Choose Subject: <select onchange="getData('post2.php?data='+this.value,
          'mydiv')" style="width:250px; height:25px; margin-left:5px" name="sub">
	<?php
				include('db.php');
				$queryn=mysql_query("SELECT * FROM  `subjects`");
				echo "<option value=none>=========Select=========</option>";
				while($rown=mysql_fetch_row($queryn))
				
				{
				 echo "<option value=$rown[0]>$rown[1]</option>";
				}
				?> 
                </select></td>
  </tr>
  <tr>
    <td colspan="2" width="400"><div id="fake" style="float:left"> Choose Mother Topic: </div> <div id="mydiv" style="float:left"> [B]Here the dropdown appears from post2.php[/B] </div>
    </td>
    <td>
    
     </td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="center">
    <input type="submit" name="post" value="Post" /> <input type="reset" name="resetall" value="Reset All" /></td>
  </tr>
</table>
</form>

That div is inside the form tag so that is not a problem.

Edited by TechySafi: n/a

0

One thing i can suggest is to use ajax again to send the data to the desired page you wish.

But before trying this,put an alert in second drop down's onChange event,just to check that option's value are alerted or not. I am sure you know how to alert option values.

Edited by Akash Saikia: n/a

0

javascript alert working fine....its showing the value on alert if I call an alert fuction onchange event.

But I don't understand why php is not taking the value?!

0

I'm not good at these stuff....basically I hardly go beyond php but now seems its a must.

Okay I will try to find some alternative.

Thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.