www.webdeveloper.com
Results 1 to 5 of 5

Thread: Unable to get select tag inside div tag being updated dynamically

  1. #1
    Join Date
    Jan 2011
    Posts
    4

    Unable to get select tag inside div tag being updated dynamically

    I have Select tag inside Div tag that is being populated dynamically from php script, I want to submit its selected value to server side script, But unable to get the value of option of Select tag.

    <Div id="selectdiv">
    <select name="CitySelect" id="CitySelect">
    <option>--Select City--</option>
    </select>

    Help will be highlly appriciated

  2. #2
    Join Date
    Nov 2010
    Location
    Los Angeles, CA
    Posts
    234
    hard to determine the problem with such little code. How are you populating the list? How are you trying to get the value of the list? What other markup is in the page?

  3. #3
    Join Date
    Dec 2002
    Location
    St. Louis, MO, USA
    Posts
    1,582
    Another thing that might help is if you "View Source" the page after it's done loading, so we can see the HTML that PHP is generating on-the-fly.

    ^_^

  4. #4
    Join Date
    Jan 2011
    Posts
    4
    Dear fellows thanks for quick reply, I am sending my php,html and js code as under, I'll be thankful for u r help
    Code:
    ////////////////////////////////////////////////////////////
    PHP Code, That will populate Select tag inside Div tag
    ////////////////////////////////////////////////////////////
    <?php
    $tehsil_id= intval($_GET['tehsil']);
    $conn = odbc_connect('jinnah_abadi','','')or die("Cannot Open DataBase");
    $query= "Select * from mouza where tehsil_id=".$tehsil_id."";
    $rcset= odbc_exec($conn,$query) or die("Error in Query");
    ?>
    	<select name="mouza" id="mouzaID" onfocus="this.value">
    <?php while(odbc_fetch_row($rcset)){?>
    	<option value="<?php odbc_result($rcset,1);?>"><?php echo odbc_result($rcset,2);?></option>
    	
    	<?php } ?></select>
    Code:
    /////////////////////////////////////////////////////////////////////////////////
    HTML CODE, for Two List Boxs and One Table
    ////////////////////////////////////////////////////////////////////////////////
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Ballotting of Jinna Abadi Scheme</title>
    <script  language="javascript" src="ballotting.js"></script>
    </head>
    <body>
    <form action="balloting.php" method="post" name="ballottingfrm" id="ballottingfrm">
    <table width="462" height="86"  border="3" bordercolor="#3300FF" align="center">
    <tr>
    	<td width="200">
        Select Teshil
    	</td>
        <td width="144">
    <select name="tehsil" onchange="getMouza(this.value)" id="tehsil">
    <option>--Select Tehsil--</option>
    <option value="0">Okara</option>
    <option value="1">Depalpur</option>
    <option value="2">RenalaKhurd</option>
    </select>
        </td>
    </tr>
    <tr>
    <td>
    Select Mouza
    </td>
    <td>
    <div id="mouzaID">
    <select name="mouza" id="mouza">
    <option>--Select Mouza--</option>
    </select>
    </div>
    </td>
    </tr>
    <td>
    Number of Plotts to Be Ballotted
    </td>
    <td>
    <input type="text" name="num"  id="num"/>
    </td>
    </tr>
    </table>
    <input type="button"  value="Ballot" onclick="submitFRM(tehsil,mouza,num)"/>
    </form>
    <table width="462" height="86"  border="3" bordercolor="#3300FF" align="center">
    <tr>
    <td><h2 align="center"> List of Successfull Applicants of Jinnah Abbadi Scheme 2011 For District Okara</h2></td>
    </tr>
    <div id="success">
    <tr>
    <td>Sr.No</td>
    <td>Application Number</td>
    <td>Computerized ID Number</td>
    <td>Name</td>
    <td>Father Name</td>
    <td>Mouza</td>
    <td>Tehile</td>
    </tr></div>
    </table>
    </body>
    </html>
    Code:
    ///////////////////////////////////////////////////////////////////////////
    JavaScript Code For Accessing Select tag inside Div tag from Form
    ////////////////////////////////////////////////////////////////////////////
    	function submitFRM(tehsil,mouza,num){
    						
    			var frmtehsil = document.getElementById('tehsil').selectedIndex
    			var tehsil = document.getElementsByTagName("option").item(frmtehsil).value;
    			var MouzaDiv = document.getElementById('mouzaID');
    			
    			var MouzaSelect = MouzaDiv.getElementsByTagName('mouza')
    			MouzaSelect;
    			
    			var m_Index = mouzaSelect.selectedIndex;
    			var frmplotnum = document.ballottingfrm.num.value;
    			alert(tehsil);
    			alert(mouzaSelect);
    			alert(frmplotnum);
    			var StrUrl= "balloting.php?tehsil="+tehsil;
    			var request= getXMLHTTP();
    			if(request){
    			request.onreadystatechange=function(){
    				
    				if(request.readyState==4){
    						if(request.status==200){
    					document.getElementById('success').innerHTML=request.responseText;
    					
    						}
    						else{
    				
    				alert("There was a Problem While Using XMLHTTP:\n"+request.statusText);
    					}
    				}
    			}
    			request.open("GET",StrUrl,true);
    			request.send(null);
    		}
    		}
    Last edited by Kor; 03-04-2011 at 07:38 AM. Reason: wrap the code [code][/code]

  5. #5
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    ?
    Code:
    var MouzaSelect = MouzaDiv.getElementsByTagName('mouza')
    			MouzaSelect;
    I suspect you wanted:
    Code:
    var MouzaSelect = document.getElementById('mouza')

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles