Hi, I have the following forms which allow the user to input the blank fields by choosing the value from dropdown list(existing data in database) or manually input the data in the blank field.
I need to do a dynamic drop-down list where after I choose the value in the 1st drop down list, the 2nd drop-downlist only consist of the values where the 1st field is the selected value. After which all the data are filled in, the form will be submitted. All the data in all the drop-down list are from the same table.
Can anyone help me?
I need to do a dynamic drop-down list where after I choose the value in the 1st drop down list, the 2nd drop-downlist only consist of the values where the 1st field is the selected value. After which all the data are filled in, the form will be submitted. All the data in all the drop-down list are from the same table.
Can anyone help me?
Code:
<!--#include file="../includes/OracleConnection.inc"-->
<!--#include file="../includes/CGI.inc"-->
<!--#include file="../includes/DBFormatFunctions.inc"-->
<html>
<body>
<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value=="")
{alert(alerttxt);return false}
else {return true}
}
}
function validate_length(field, max_length, alerttxt)
{
with (field)
{
if (value.length>max_length)
{alert(alerttxt);return false}
else {return true}
}
}
function isNumericOrDecimal(field)
{
var checkOK = "0123456789.";
var checkStr = field.value;
var allValid = true;
var allNum = "";
for (i = 0; i < checkStr.length; i++) {
ch = checkStr.charAt(i);
for (j = 0; j < checkOK.length; j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length) {
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid) {
return false;
}
}
function isInteger(s){
var i;
for (i = 0; i < s.length; i++){
// Check that current character is number.
var c = s.charAt(i);
if (((c < "0") || (c > "9"))) return false;
}
// All characters are numbers.
return true;
}
function validate_form2(thisform)
{
with (thisform)
{
if (validate_required(txtselName,"Please Enter Subcontractor Name")==false)
{txtselName.focus();return false}
if (validate_length(txtselName, 30, "You have entered " + txtselName.value.length + " characters for Subcontractor Name\nPlease enter less than 30 characters")==false)
{txtselName.focus();return false}
if (validate_required(txtselYear,"Please Enter Year")==false)
{txtselYear.focus();return false}
if (validate_length(txtselYear, 4, "You have entered " + txtselYear.value.length + " characters for Year\nPlease enter less than 5 characters")==false)
{txtselYear.focus();return false}
if (insert_subcon_ratings_records.txtselYear.value!="")
{
if (!isInteger(txtselYear.value))
{
mesg = "You have entered <" + insert_subcon_ratings_records.txtselYear.value + "> for Year\n"
mesg = mesg + "Please enter a 4-digit numerical value."
alert(mesg)
insert_subcon_ratings_records.txtselYear.focus();
return false;
}
}
if (insert_subcon_ratings_records.txtselRating.value > 100)
{
mesg = "You have entered <" + insert_subcon_ratings_records.txtselRating.value + "> for Rating\n"
mesg = mesg + "Please enter a number less than 101."
alert(mesg);
insert_subcon_ratings_records.txtselRating.focus();
return (false);
}
if (insert_subcon_ratings_records.txtselRating.value!="")
{
if (isNumericOrDecimal(txtselRating)== false)
{
mesg = "You have entered <" + insert_subcon_ratings_records.txtselRating.value + "> for Ratings\n"
mesg = mesg + "Please enter a numerical value."
alert(mesg)
insert_subcon_ratings_records.txtselRating.focus();
return false;
}
}
}
}
function setoption(frmname,which)
{
frmname['txt'+which].value = (frmname[which].options(frmname[which].selectedIndex).text);
}
</script>
<form name="insert_subcon_ratings_records" method="Post" action="insert_subcon_ratings_records.asp" onsubmit="return validate_form2(this)">
<table>
<tr><td width=180><font color=red>*</font>Subcontractor Name: </td>
<td bgcolor="red"><input type=text name="txtselName" size="50"/>
</td><td>
<select style="width: 200px" name="selName" onchange="setoption(this.form,this.name)">
<%
sql1="SELECT DISTINCT NAME from subdb_subcon_rating"
Set rs1 = OraDatabase.Execute(sql1)
response.write ("<option value=""""></option>")
Do While Not rs1.EOF
IF Request("selName") = rs1("NAME") THEN
response.write ("<option value="""&rs1("NAME")&""" selected >"&rs1("NAME")&"</option>")
ELSE
response.write ("<option value="""&rs1("NAME")&""">"&rs1("NAME")&"</option>")
END IF
rs1.MoveNext
Loop
%>
</select>
</td></tr>
<tr><td><font color=red>*</font>Year: </td>
<td bgcolor="red"><input type=text name="txtselYear" size="50"/>
</td><td>
<select style="width: 200px" name="selYear" onchange="setoption(this.form,this.name)">
<%
sql2="SELECT DISTINCT YEAR from subdb_subcon_rating"
Set rs2 = OraDatabase.Execute(sql2)
response.write ("<option value=""""></option>")
Do While Not rs2.EOF
IF Request("selYear") = rs2("YEAR") THEN
response.write ("<option value="""&rs2("YEAR")&""" selected >"&rs2("YEAR")&"</option>")
ELSE
response.write ("<option value="""&rs2("YEAR")&""">"&rs2("YEAR")&"</option>")
END IF
rs2.MoveNext
Loop
%>
</select>
</td></tr>
<tr><td>Rating/100: </td>
<td><input type=text name="txtselRating" size="50"/>
</td><td>
<select style="width: 200px" name="selRating" onchange="setoption(this.form,this.name)">
<%
sql3="SELECT DISTINCT RATING from subdb_subcon_rating"
Set rs3 = OraDatabase.Execute(sql3)
response.write ("<option value=""""></option>")
Do While Not rs3.EOF
IF Request("selRating") = rs3("RATING") THEN
response.write ("<option value="""&rs3("RATING")&""" selected >"&rs3("RATING")&"</option>")
ELSE
response.write ("<option value="""&rs3("RATING")&""">"&rs3("RATING")&"</option>")
END IF
rs3.MoveNext
Loop
%>
</select>
</td></tr>
</table><br>
<input type="submit" name="submit_subcon_ratings_records" value="Submit Ratings Records">
<input type="reset" name="reset_subcon_ratings_records" value="Reset">
</form>
</body>
</html>