Home > ASP Development > Textarea problem

Textarea problem



Hi,



i have 2 tables

one table stores the information for the prof and second table stores information for the subject he teaches

so first table deptprof has the id,name,email for the professor



so i get his last name and email which is working

second table design is name is deptlist

fields are



deptautoid

deptid

subjectname

desc



so one professor might be teaching 3 subjects



so the records in table are



1001

3

maths

maths subject is boring





1002

3

science

science is good



1003

3

sports

make some time for it



so now this page lets the professor update the subject and its desc



so what i do is fill up the subjects and desc he is currently assigned to and then he can change the subjects

and desc



subjects have a checkbox and desc has a textarea



what happens is for example a professor has 3 subjects he is teaching now



so 3 checkboxes are selected and all the desc for them are displayed in the textarea



but now the professor decides he wants to teach 4 subjects

so he selects the 4th subject checkbox and doesnt enter the desc i want to fire the alert



but it doesnt fire the alert



second way prof is teaching 3 subjects

3 checkboxes are selected and 3 textarea are filled



professor decides to delete desc in one of them and hits submit i want to fire an alert

saying he forget desc but it doesnt fire so whenver desc is deleted from the textarea and checkbox for it is selected

i want to fire an alert



can someone tell me whats wrong with the code



thanks,



todd


Code:




<%



getid=trim(request.form("id"))

sqlstr = "SELECT *FROM deptprof WHERE ID = '" & getid & "'"
Set rsdept = Conn.Execute(sqlstr)

getlname=rsdept("LastName")
getemail=rsdept("Email")

rsdept.close
Set rsdept=nothing


sqldeptdetails = "SELECT *FROM deptlist WHERE deptid = '" & getid & "'"
Set rsDetails = Conn.Execute(sqldeptdetails)

%>




<head>
<title>Dept List</title>
<script type="text/javascript">
<!--
function formCheck(formobj)
{
var fieldRequired = Array('LName', 'Email');
var fieldDescription = Array('Last Name', 'Email');

var alertMsg = "You can't submit the form until ALL the mandatory fields have been filled out.\n";
alertMsg += '_________________________________________________ ___\n\n'
alertMsg += "Please complete the following fields, then press 'Update dept':\n\n";
var c = 0;
for (var i = 0; i < fieldRequired.length; i++)
{
var obj = formobj.elements[fieldRequired[i]];
document.getElementById(fieldRequired[i]).style.backgroundColor = '#' +'ffffff';
if (obj)
{
switch(obj.type)
{
case 'select':
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == '')
{
alertMsg += ' - ' + fieldDescription[i] + '\n';
document.getElementById(fieldRequired[i]).style.backgroundColor = '#' + 'f8e563';
c++;
}
break;
case 'text':
case 'textarea':
if (obj.value == '' || obj.value == null)
{
alertMsg += ' - ' + fieldDescription[i] + '\n';
document.getElementById(fieldRequired[i]).style.backgroundColor = '#' + 'f8e563';
c++;
}
break;
default:
if (obj.value == '' || obj.value == null)
{
alertMsg += ' - ' + fieldDescription[i] + '\n';
document.getElementById(fieldRequired[i]).style.backgroudColor = '#' + 'f8e563';
c++;
}
}
}
}
alertMsg += '\nThese fields have been highlighted for your attention.';
if (c == 0)
{



var strGroupName="rad1";
var checkedCount=0;
for (var i=0; i<document.frm1.elements[strGroupName].length; i++)
{

var curBox=document.frm1.elements[strGroupName][i];

if (curBox.checked)
{

if (document.frm1.elements["txt"+(i+1)].value=='')
{

alertMsg += "Please complete the following fields, then press 'update dept':\n\n";
alertMsg += "You have not entered the value for the "+(i+1)+" Specify desc \n\n";
alert(alertMsg);
document.frm1.elements["txt"+(i+1)].focus(0);
return false;

}
}

}


document.getElementById('submit').value = 'Next...';
return true;
}

else
{
alert(alertMsg);
c = 0;
return false;
}

}

//-->
</script>

</head>
<body>

<form name="frm1" method="post" action="conflist.asp" onsubmit="return formCheck(this);">

<p>Last name:<input type="text" size="32" name="LName" id="LName" value="<%=getlname%>"><br/>
<p>Email:<input type="text" size="32" name="Email" id="Email" value="<%=getemail%>" /><br/>


<table>
<tr>
<th>No</th>
<th>Dept</th>
<th>Desc</th>
</tr>


<tr class="evenrow">
<td>1.</td>
<td><input type="checkbox" name="rad1" value="Maths"
<%
do while not rs.eof
if rsDetails("subjectname") ="Maths" then
Response.Write "checked"
end if
rsDetails.movenext
loop
rsDetails.movefirst
%>

>
Maths</td>

<td><textarea name="txt1" id="txt1" rows="2" cols="35">
<%
Dim rs1,sqlr1,raexp1
raexp1="Maths"

sqlr1 = "SELECT desc FROM deptlist WHERE deptid = '" & getid & "' and subjectname='" & raexp1 & "'"
Set rs1= Conn.Execute(sqlr1)

if not rs1.eof then
%>

<%=rs1("desc")%>
<%

else

End if

rs1.close
Set rs1=nothing
%>

</textarea></td>
</tr>

<tr class="oddrow">
<td>2.</td>
<td><input type="checkbox" name="rad1" value="Science"

<%

do while not rsDetails.eof

if rsDetails("subjectname") ="Science" then
Response.Write "checked"
end if

rsDetails.movenext
loop
rsDetails.movefirst

%>
>Science</td>

<td><textarea name="txt2" rows="2" cols="35">
<%
Dim rs2,sqlr2,raexp2
raexp2="Science"

sqlr2 = "SELECT desc FROM deptlist WHERE deptid = '" & getid & "' and subjectname='" & raexp2 & "'"
Set rs2= Conn.Execute(sqlr2)

if not rs2.eof then
%>


<%=rs2("desc")%>
<%
else

End if

rs2.close
Set rs2=nothing
%>

</textarea></td>
</tr>

<tr class="evenrow">
<td>3.</td>
<td><input type="checkbox" name="rad1" value="sports"
<%

do while not rsDetails.eof

if rsDetails("subjectname") ="sports" then
Response.Write "checked"
end if

rsDetails.movenext
loop
rsDetails.movefirst

%>


>sports</td>
<td><textarea name="txt3" rows="2" cols="35">
<%
Dim rs3,sqlr3,raexp3
raexp3="sports"

sqlr3 = "SELECT desc FROM deptlist WHERE deptid = '" & getid & "' and subjectname='" & raexp3 & "'"
Set rs3= Conn.Execute(sqlr3)

if not rs3.eof then
%>

<%=rs3("desc")%>
<%
Else

End if

rs3.close
Set rs3=nothing
%>

</textarea></td>
</tr>

<tr class="oddrow">
<td>4.</td>
<td><input type="checkbox" name="rad1" value="arts"
<%

do while not rsDetails.eof

if rsDetails("subjectname") ="arts" then
Response.Write "checked"
end if

rsDetails.movenext
loop
rsDetails.movefirst

%>

>arts</td>
<td><textarea name="txt4" rows="2" cols="35">
<%
Dim rs4,sqlr4,raexp4
raexp4="arts"

sqlr4 = "SELECT desc FROM deptlist WHERE deptid = '" & getid & "' and subjectname='" & raexp4 & "'"
Set rs4= Conn.Execute(sqlr4)

if not rs4.eof then
%>

<%=rs4("desc")%>
<%
Else

End if

rs4.close
Set rs4=nothing
%>

</textarea></td>
</tr>


<tr class="evenrow">
<td>5.</td>
<td><input type="checkbox" name="rad1" value="computers"

<%

do while not rsDetails.eof

if rsDetails("subjectname") ="computers" then
Response.Write "checked"
end if

rsDetails.movenext
loop
rsDetails.movefirst

%>

>computers</td>
<td><textarea name="txt5" rows="2" cols="35">
<%
Dim rs5,sqlr5,raexp5
raexp5="computers"

sqlr5 = "SELECT desc FROM deptlist WHERE deptid = '" & getid & "' and subjectname='" & raexp5 & "'"
Set rs5= Conn.Execute(sqlr5)

if not rs5.eof then
%>

<%=rs5("desc")%>
<%
Else

End if

rs5.close
Set rs5=nothing
%>

</textarea></td>
</tr>


</table>


<p><input class="button" type="Submit" id="Submit" value="Update Dept" /><input class="button" type="reset" id="reset" value="Clear" /></p>

<%
Conn.close
Set Conn=Nothing
%>

</form>
</body>
</html>



    
Guest


It sounds as if the design for this application is flawed.

Was this answer helpful ? Yes No   
Guest


memnoch,



is there any other way i can do it



thanks,



todd

Was this answer helpful ? Yes No   
Guest


hi,



it doesnt throw the alert neither does it submit the page

so checked in mozilla and this is the error it gives



Error: document.getElementById(fieldRequired[i]) has no properties



which is on this line



document.getElementById(fieldRequired[i]).style.backgroundColor = '#' + 'ffffff';





thanks,



todd

Was this answer helpful ? Yes No   
Guest


This is a javascript problem, not ASP.

Also, you should not rely on Javascript validation as it can be bypassed.

Was this answer helpful ? Yes No   
Guest


any ideas guys



thanks,



todd

Was this answer helpful ? Yes No   
Guest


For one, you have a spelling error


Code:



backgroudColor






Post the source code of your page when it is opened in a browser.

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved