Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Posting form that has ajax generated data -not posting

Posted on 2013-01-26
1
614 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

860 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