Solved

Posting form that has ajax generated data -not posting

Posted on 2013-01-26
1
613 Views
Last Modified: 2013-01-27
I have a form that loads a select populated with a list of teacher names.  When the teacher name is selected a series of checkboxes are loaded with regions.  A teacher can have multiple regions.  The data is then submitted...but the ajax generated data is not transmitting.  How do I do this?


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Admin Teachers</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" >
<meta name="robots" content="noindex,nofollow" >
<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<link rel="stylesheet" href="style.css" type="text/css"  >
<link rel="stylesheet" href="pagestyle.css" type="text/css"  >
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script>
$(document).ready(function() {
    $("#content div").hide(); // Initially hide all content
    $("#tabs li:first").attr("id","current"); // Activate first tab
    $("#content div:first").fadeIn(); // Show first tab content
   
    $('#tabs a').click(function(e) {
        e.preventDefault();
        if ($(this).closest("li").attr("id") == "current"){ //detection for current tab
         return      
        }
        else{            
        $("#content div").hide(); //Hide all content
        $("#tabs li").attr("id",""); //Reset id's
        $(this).parent().attr("id","current"); // Activate this
        $('#' + $(this).attr('name')).fadeIn(); // Show content for current tab
        }
    });
});
</script>
<script>
function getTeacherRegions(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","teacher_regions_query.asp?teacher_id="+str,true);
xmlhttp.send();
}
</script>  

</head>
<body>



<ul id="tabs">
<li><a href="#" name="tab3">Teachers</a></li>
    <li><a href="#" name="tab1">Website Pages</a></li>
    <li><a href="#" name="tab2">Students</a></li>
   
    <li><a href="#" name="tab4">Resources</a></li>    
     <li><a href="#" name="tab5">On Hold</a></li>  
     <li><a href="#" name="tab6">Royalties</a></li>
      <li><a href="#" name="tab7">Courses</a></li>
       <li><a href="#" name="tab8">Misc Admin</a></li>  
</ul>

<div id="content">

<div id="tab3">
 
 <p><!--#include file="teachers_toplinks.html"--></p>
        <h2>Edit Teaching Regions</h2>
 <p><%response.write TheMessage%>&nbsp;</br> </p>        
      
<p>
<form method="POST" action="A2edit_teachingregions_2db.asp" style="text-align: center"  name="form1"  >

<table style="border-color: #BBDDFF" cellspacing="0" cellpadding="0" width="700">


 


<tr><td style="vertical-align: middle; border-color: #BBDDFF" height="30">Teacher Name</td>
<td style="vertical-align: middle; border-color: #BBDDFF" height="30">

<select name="teacher_id" id="teacher_id" onchange="getTeacherRegions(this.value);"  >
<option value="">Select a Teacher</option>

                              <%dim objC2,strC2
                              strC2="SELECT teachers.teacher_id,teachers.teacher_first_name,teachers.teacher_last_name FROM teachers,teacher_info where teacher_info.teacher_id=teachers.teacher_id and teacher_info.status='A' order by teachers.teacher_first_name"
                              
                              set objC2=Server.CreateObject("ADODB.Recordset")
                              objC2.open strC2, objConn
                              
                              while not objC2.eof
 
                                    
                                    %>
                                    <option value="<%response.write objC2("teacher_id")%>"><%response.write objC2("teacher_first_name")&" "&objC2("teacher_last_name")%></option>
                                    <%
                                    objC2.movenext
                              wend
                              objC2.close
                              set objC2=nothing
                              
                  
                              
                              %>
                              </select> <br>
 

<tr><td colspan="2"> <p id="txtHint"><b>Region info will be listed here.</b></p></td></tr>
 <tr><td style="text-align: center; vertical-align: middle; border-color: #BBDDFF" height="30" colspan="2">
 
    <input type="button" name="submit" value="submit"  />      
  </td></tr>
</table>      
</form> </p>
</div>
    <div id="tab1">
    <h2>Web Pages</h2>  
 <p><!--#include file="webpages_toplinks.html"--></p>

</div>
<div id="tab2">
    <h2>Students</h2>
   <p>Under Construction</p>  
</div>
<div id="tab4">
    <h2>Resources</h2>
  <p>Under Construction</p>  
</div>
    <div id="tab5">
    <h2>On Hold</h2>
    <p>Under Construction</p>    
</div>
    <div id="tab6">
    <h2>Royalties</h2>
    <p>Under Construction</p>    
</div>
    <div id="tab7">
    <h2>Courses</h2>
    <p>Under Construction</p>    
</div>
    <div id="tab8">
    <h2>Miscellaneous</h2>
    <p>Under Construction</h3>

</div>
</div>
</body>
</html>

--teacher_regions_query.asp-------------------------------------------------------
<%@Language=vbscript%>  
 
<!--#include virtual="adovbs.inc"-->
<!--#include file="databaseconnect.asp"-->


<%
'teacher_id=1
teacher_id=request.querystring("teacher_id")

dim region_id,objREG,strREG,region,numberofboxes
dim  objREG2,strREG2,count
count=0
 

'strREG2="SELECT * from regions where region_id IN (SELECT region_id from teachers_regions where teacher_id='"&teacher_id&"' )"
strREG="SELECT regions.region_id,regions.region from regions,teachers_regions where teachers_regions.teacher_id='"&teacher_id&"' and teachers_regions.region_id=regions.region_id"

set objREG = Server.CreateObject("ADODB.Recordset")
objREG.open strREG, objConn      

while not objREG.eof
      count=count+1
      region=objREG("region")
      region_id=objREG("region_id")      
 %>
      <input type="checkbox" name="<%response.write "regionF"&count%>" value="<%=region_id%>" checked>&nbsp;&nbsp;&nbsp;<%response.write region%><br>
      
<%
      
objREG.movenext
wend
strREG2="SELECT * from regions where region_id NOT IN (SELECT region_id from teachers_regions where teacher_id='"&teacher_id&"' )"
 

set objREG2 = Server.CreateObject("ADODB.Recordset")
objREG2.open strREG2, objConn      

while not objREG2.eof
      count=count+1
      region=objREG2("region")
      region_id=objREG2("region_id")%>      
      
      <input type="checkbox" name="<%response.write "regionF"&count%>" value="<%=region_id%>"  >&nbsp;&nbsp;&nbsp;<%response.write region%><br>

<%
       
objREG2.movenext
wend
numberofboxes=count%>
<input type="hidden" name="numberofboxes" value="<%=numberofboxes%>">
<%'response.write numberofboxes
%>

--A2edit_teachingregions_db.asp-------------------------------------------------------------------------
<%@Language=vbscript%>  
 <% Option Explicit %>
<!--#include virtual="adovbs.inc"-->
<!--#include file="databaseconnect.asp"-->
 
<!--#include file="A2adminheader.asp"-->
 

<!--#include file="ErrorHandling.asp"-->

<%
' Turn on page buffering
 Response.Buffer = True
 
 ' Turn On Error Handling
 On Error Resume Next
'delete all records in teachers_regions for this teacher
dim objDelete,strDelete,i,teacher_id

teacher_id=request.form("teacher_id")
response.write teacher_id
response.write "<br/>"

 
objConn.execute "Delete from teachers_regions WHERE teacher_id='"&teacher_id&"'"



Dim numberofboxes
numberofboxes= request("numberofboxes")
dim objC4,strC4
 
teacher_id=request.form("teacher_id")
 
 
      
       'step through the regions and post to teachers_regions
      
       for i=1 to numberofboxes
             response.write i
             response.write "<br/>"
             region_id=request.form("regionF1")
             response.write region_id
             if region_id=1 then
                    
                   strC4="Insert into teachers_regions (teacher_id,region_id) VALUES ('"&teacher_id&"','"&region_id&"')"
                   response.write strC4
                   response.write "<br/>"
                  Set objC4 = Server.CreateObject("ADODB.Recordset")
                  objC4.Open  strC4, objConn
      
                   If Err.number <> 0 then
                        TrapError Err.description
                        ErrorMessage="An Error Has occured in the regions database insert"
                        response.redirect "webpage_error.asp?ErrorMessage='"&ErrorMessage&"' "
                  
                  End If
             
             end if
       next      
      

response.redirect "A2edit_teachingregions.asp"

%>
0
Comment
Question by:vmoore99
1 Comment
 
LVL 11

Accepted Solution

by:
mcnute earned 415 total points
ID: 38824144
Check first if it has been loaded when a teacher has been selected by printing it out in the console like so:

console.log(data);

Open in new window


This will give you certainty it the data is there. The console works in firebug(firefox developer plugin and in google chrome developer tools)

Next step look if the data has been written in the fields you're submitting afterwards.

And then tell us what happened if that didn't lead to a solution.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jquery, dropdown 4 61
Generate report pulling data (links) from three tables 31 64
Auto refresh part of an MVC5 View 7 93
PHP AJAX JSON 2 60
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question