Hi
I will appreaciate it if someone could have a look at this form and help me with the following issues. I am very new to java and have put the java part together from code on the net. The form is filled in and is writin to a sql database by save.asp that does all that logic.
1.) The requirement is a competency field where the user is able to do a selection and ad a percentage. This is working OK as I concatinate the List value and the txt box + %. I have done this with the idea that once I get these values in query string I can handle them appropiately on server side before the insert.
In the same field I have got a txt box that I would like to add up the percentages and diplay an alert when selctions exceed 100 I have managed to do a + on these values but it just concatinates instead of add. I believe this is because the values rae handled as variant instead of intiger. I have tried using int(string) + int(string2) but I get errors....And Im new to java I need to figure this out and it is holding the project. So any advice appreciated.
2.) On the same competency field the second list which contains the Concatinated value + the % does not get passed onto the query string. I belive it is because there is no ID property. I have got no idea how to assign an ID property with the java part. Also even if there is a property it will only pass the selected one in string? So I need a way to pass all the values to my save.asp to write to the database....any sugestions??
Below is the code for the form. I know it will take some time to figure out what I did here but any help appreciated...
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>New Opportunity</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<%varDate = formatDateTime(Date(),2)%>
<SCRIPT language="JavaScript">
function Validate() {
// define a variable to hold an error message.
//alert(document.forms[0].elements[5].type)
var strErrorMessage = String("") ;
var varPassed ;
var varReasonFailed ;
// Get a handle to our form object.
var f = form1 ;
// Update the value in our hidden field, so that we know what
// button was pressed.
// f.hidAction.value = s.name ;
// Declare which fields are optional.
f.Reset.optional = true ;
f.Perc.optional = true;
f.Competency.optional = true;
f.JntVentPart.optional = true;
f.Competition.optional = true;
f.CompValues.optional = true;
//n is for the
vb split function on required.asp...know how many splits to do??:)
n = 0;
// Declare which fields are supposed to be numeric.
f.ClientTel.numeric = true ;
f.TotalOppVal.numeric = true ;
f.DCVal.numeric = true ;
f.PotRevenue.numeric = true ;
// Iterate through the elements on our form and validate them
// as we go.
for(var i=0; i<=f.elements.length-1; i++) {
varPassed = "PASSED" ;
varReasonFailed = "" ;
// Get a handle to the current element.
var e = f.elements[i] ;
// We'll store the value of the element in a variable.
var ElementValue = "" ;
// Use a switch statement to work out what type of element
// we have, because we get the value of different elements
// in differing ways.
switch(e.type) {
case "text":
ElementValue = e.value ;
break ;
case "select-one":
ElementValue = e[e.selectedIndex].id ;
break ;
case "textarea":
ElementValue = e.value ;
break ;
}
// OK, we're not interested in Hidden Fields,Buttons,
// or Optional fields so skip them
if( e.type != "hidden" && e.type != "button" && !e.optional )
{
// Once we get here we need to make sure that the user has entered some
// sort of entry (in other words - make sure that the field isn't empty).
if ( ElementValue == null || ElementValue == "" ) {
// If the field is empty then we append a message to our Error Message
// string.
strErrorMessage += e.id + ".\n" ;
varPassed = "FAILED" ;
n = n + 1;
varReasonFailed += "Because no value was entered.\n" ;
}
}
// Now validate the fields that are supposed to be numeric.
if(e.numeric == true) {
if( isNaN(ElementValue) ) {
// The user entered a non-numeric value where a
// numeric value was required.
strErrorMessage += "Enter a numeric value for " + e.id + ".\n" ;
varPassed = "FAILED" ;
n = n + 1;
varReasonFailed += "Because the value entered was not numeric.\n" ;
}
}
if(e.numeric == false) {
if( !isNaN(ElementValue) && ElementValue != null && ElementValue != "" ) {
// The user entered a non-numeric value where a
// numeric value was required.
strErrorMessage += "You cannot enter a numeric value for " + e.id + ".\n" ;
varPassed = "FAILED" ;
n = n + 1;
varReasonFailed += "Because the value entered was numeric." ;
}
}
var strDetails = ""
strDetails += "VALIDATING: " + e.id + "\n"
strDetails += "-------------------------------------------\n\n"
strDetails += "TYPE: " + e.type + ",\n"
strDetails += "VALUE: " + ElementValue + ",\n"
strDetails += "NUMERIC: " + e.numeric + ",\n"
strDetails += "OPTIONAL: " + e.optional + ".\n\n"
strDetails += "This element " + varPassed + " the validation\n"
strDetails += varReasonFailed ;
//alert(strDetails) ;
}
// If there is an error message, display it to the user, otherwise,
// submit the form.
if (strErrorMessage.length >= 1) {
msgWindow = window.open('','newWin','width=300,height=380,scre enX=400,screenY=400,top=200,left=350');
//open the window and pass the error and count of errors
msgWindow.location.href = 'required.asp?Error=' + strErrorMessage + "&Count=" + n ;
} else {
f.submit() ;
}
}
//Start Of Competency Function
function dosubmit() {}
function deleteOption(object,index) {
//Alert(object.options[index]);
object.options[index] = null;
}
function addOption(object,text,value) {
var defaultSelected = true;
var selected = true;
//Get % selection
var Percentage = document.forms[0].elements[5].value;
//Incriment the value so users dont exceed 100%
document.forms[0].elements[9].value = document.forms[0].elements[9].value + document.forms[0].elements[5].value;
//Set the value
var optionName = new Option(text + ", " + document.forms[0].elements[5].value + "%", value, defaultSelected, selected)
object.options[object.length] = optionName;
object.options[object.id] = "A";
//Set the original typed in % back to 0
document.forms[0].elements[5].value = "0";
}
function copySelected(fromObject,toObject) {
for (var i=0, l=fromObject.options.length;i<l;i++) {
if (fromObject.options[i].selected)
addOption(toObject,fromObject.options[i].text,fromObject.options[i].value);
}
for (var i=fromObject.options.length-1;i>-1;i--) {
if (fromObject.options[i].selected)
deleteOption(fromObject,i);
}
}
</script>
</head>
<body>
<table align="center">
<tr>
<td>|</td>
<td><a href="Default.asp" title="Return Home">Home</a></td>
<td>|</td>
<td><a href="Browse.asp" title="Click to Go To My Documents">My Documents</a></td>
<td>|</td>
<td><a href="My Reports.asp" title="Click to Go To Reports">My Reports</a></td>
<td>|</td>
<td><A HREF="javascript
:history.back()" title="Back">Back</A></td>
<td>|</td>
</tr>
</table>
<table width="75%" border="0">
<tr>
<td><b>Deloitte
Consulting</b></td>
</tr>
<tr>
<td>Opportunity
Register</td>
</tr>
</table>
<form name="form1" method="Get" action="save.asp?">
<table width="70%" height="511" align="center">
<tr><td>*<i>Indicates Required Field</i></td></tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Holding
Company:*</td>
<td>
<input type="text" name="HoldingCo" width="250" id="Holding Company">
</td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Client/Div:*</td>
<td>
<input name="ClientDiv" type="text" id="Client Div">
</td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Industry:*</td>
<td>
<select name="Industry" id="Industry">
<option></option>
<option id="1">Manufacturing</option>
<option id="2">Energy</option>
<option id="3">Communications</option>
<option id="4">Financial Services</option>
<option id="5">Consumer Business</option>
<option id="6">Public Sector</option>
<option id="7">Other</option>
</select>
</td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Service
Area:*</td>
<td>
<input type="text" name="ServiceArea" width="250" id="Service Area">
</td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Compentency:*</td>
<td><table><tr><td><select name="Competency" ID = "Competency">
<option>Strategy & Operations</option>
<option>BPO</option>
<option>Outsourcing</option>
<option>Human Capital</option>
<option>Technology</option>
<option>Enterprise Applications - SAP</option>
<option>Enterprise Applications - P/Soft</option>
</select></td><td><input name="Perc" type="text" value="0" id = "Percentage" size="2" maxlength="3">%</td>
<td><input type="button" value=" > "
onClick="copySelected(this.form.Competency,this.fo rm.CompValues), dosubmit(CompValues)"> <p><input
type="button" value=" < "
onClick="copySelected(this.form.CompValues,this.fo rm.Competency), dosubmit(CompValues)"> </p>
</td>
<td><select name="CompValues" multiple id="Competency Values">
</select> </td><td><input name="Calc" type="text" value="0" id = "Calc" size="2" maxlength="3"></td>
</tr></table>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Status:*</td>
<td>
<select name="StatusA" id="Status">
<option></option>
<option id="1">1. Won</option>
<option id="2">2. Negotiations/Short List</option>
<option id="3">3. Proposal Submitted</option>
<option id="4">4. Proposal In Progress</option>
<option id="5">5. Qualified Oportunity</option>
</select>
</td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Partner
Responsible:*</td>
<td><select name="PartnerRes" id="Partner Responsible"><option></option>
<%
'Ok...Get data as per users table where part = y
Set cnn = Server.CreateObject("ADODB.Connection")
cnn.Open ConnectString
SQL = "Select FullName From tbl_Users Where PartnerY = 'Y' Order By FullName"
Set RS = cnn.Execute(SQL)
Do Until rs.eof
%>
<option id=<%=rs("FullName")%>><%=rs("FullName")%></option>
<%
rs.movenext
loop
Set rs = Nothing
Set cnn = Nothing
%>
</select></td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Client Contact:*</td>
<td>
<input type="text" name="ClientContact" width="250" id="Client Contact">
</td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<tr>
<td height="25">Manager:*</td>
<td>
<input type="text" name="Manager" width="250" id="Manager">
</td>
</tr>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td height="25">Joint Venture Partner:</td>
<td>
<input type="text" name="JntVentPart" width="250" id="Joint Venrure Partner">
</td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td height="25">Competition:</td>
<td>
<input type="text" name="Competition" width="250" id="Competition">
</td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Marketing Involved:*</td>
<td>
<select name="Marketing" id="Marketing Involved">
<option></option>
<option id="0">Yes</option>
<option id="1">No</option>
</select>
</td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Client Contact:*</td>
<td>
<input type="text" name="ClientContact" width="250" id="Client Contact">
</td>
</tr>
<tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<tr>
<td height="25">Client
Tel No:*</td>
<td>
<input type="text" name="ClientTel" width="250" id="Client Tel">
<i>"()","space","-" is invalid</i></td>
</tr>
<tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Total Value
of Opportunity:*</td>
<td>
<input type="text" name="TotalOppVal" width="250" id="Total Value of Opportunity">
<i>Only Numeric Values Allowed</i></td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Total NSR
for Consulting:*</td>
<td>
<input type="text" name="DCVal" width="250" id="Total Value for Consulting">
<i>Only Numeric Values Allowed</i></td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Potential
Revenue for <%=cFY%>:*</td>
<td>
<input type="text" name="PotRevenue" width="250" id="Potential Revenue">
<i>Only Numeric Values Allowed</i></td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
<tr>
<td>Opportunity
Description:*</td>
<td>
<textarea name="OppDesc" id="Opportunity Description" cols="50" rows="9"></textarea>
</td>
</tr>
<tr><td bgcolor="#CCCCCC" width="204"></td><td bgcolor="#CCCCCC" width="467"></td></tr>
</table>
<table align="center">
<tr>
<td><input name="Save" type="button" value="Save" onClick="Validate()"></td>
<td><input name="Reset" type="reset" value="Clear"></td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
</body>
</html>
Thanks in advance
Regards
Marnus