Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2004, 11:16 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default List box does not submit to query string

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=" &gt; "
      onClick="copySelected(this.form.Competency,this.fo rm.CompValues), dosubmit(CompValues)"> <p><input
      type="button" value=" &lt; "
      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>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>

Thanks in advance

Regards
Marnus
 
Old July 20th, 2004, 11:36 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

Just to add onto this incase someone have got a better solution.

Because the competencies are broken up into multiple % I have got an extra table for this which is linked to the main table (1-M). All the data is writin to the main table by save.asp and then I get the ref no. I then need to write the Competency seperately into 2 fields. Competency and Percentage. With the list box I suspect data comming in as some array So each var will have "Value, 10%" I will then drop the % and spilt on "," and then insert. So to add onto the second question, I basicly need to add every value in the Second listbox into same array and pass it to my save.asp.

Thanks
Marnus
 
Old July 20th, 2004, 09:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Marnus,

Let us try and solve this one by one.

Change your addOption() code to this.

Code:
function addOption(object,text,value) {
var defaultSelected = true;
var selected = true;
//Get % selection
var Percentage = document.form1.Perc.value;
//Incriment the value so users dont exceed 100%
var Total = document.form1.Calc.value;
Total = parseInt(Total) + parseInt(Percentage);
//alert(Total);
//Set the value
var optionName = new Option(text + ", " + Percentage + "%", value, defaultSelected, selected)
object.options[object.length] = optionName;
//object.options[object.id] = "A";
//Set the original typed in % back to 0
document.form1.Perc.value = 0;
document.form1.Calc.value = Total;
}
Why don't you use FORMNAME and CONTROLNAME referencing, instead of using subscript referencing of FORM and ELEMENT collections. That makes a programmer's job tough unless you want to handle that dynamically.

What is that getting passed with value the 3rd parameter in the above function? I don't see any value coming along with it.

IMO, you should use different functions for < and > operations, as < operation deals with parsing the value in the right-side list box and replacing only the first part of its value in the left-side list box.

Also, I am not sure why you are using a GET method in the form. Is there any reason to do that rather than using POST method. We will come to that later.

Hope this helps.
Cheers!

_________________________
- Vijay G
Strive for Perfection
 
Old July 21st, 2004, 03:28 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default

Hi

Thanks for that...think I have realised now that javascript is case sensitive. :D

Ok, I have changed the AddOption Function to do alert when 100% is reached and then not insert the value. It looks like this now:

function addOption(object,text,value) {
    var defaultSelected = true;
    var selected = true;
    //Get % selection
    var Percentage = document.form1.Perc.value;
    //Incriment the value so users dont exceed 100%
    var Total = document.form1.Calc.value;
    Total = parseInt(Total) + parseInt(Percentage);
    document.form1.Calc.value = Total;
        if (document.form1.Calc.value > 100) {
            alert("Total Cannot exceed a 100%");
            Total = parseInt(Total) - parseInt(Percentage);
            document.form1.Calc.value = Total;
        }else{
        //Set the value
        var optionName = new Option(text + ", " + Percentage + "%", value, defaultSelected, selected);
        object.options[object.length] = optionName;
        }
//object.options[object.id] = "A";
//Set the original typed in % back to 0
document.form1.Perc.value = 0;

}

Now the next chalenge is to do the Remove button. This uses the same functions and just passed the FromObject and ToObject Around. Like u said I will need to split the < & > functions as they wont be doin the same thing anylonger. So I need to Remove the percentage and comma again and deduct the percentage from the Calc txt Box(total). I will try and use the "stringObj.split([separator[, limit]])" split method for this? I should be able to figure this one out. (I hope)

I use Get for making my life easier at the moment for trouble shooting and I am not really bothered if the user see what is being passed where. Is there any other good reason I should rather use post?

Now the next challenge is to get ALL the values in "CompValues" into some array I can pass to the save page. At the moment in the querystring it turns out "&CompValues="

I was thinking of adding a small loop typa java piece within the Valadation Function, right ontop. Then I can build an array with all the values and set some hidden objects value to that array, validate the hidden object for blank and then submit. Could u point me in the right direction again on this one?

Thanks for ur previous post!
Regards
Marnus





Similar Threads
Thread Thread Starter Forum Replies Last Post
Query Criteria through List Box atiftanveer Access 1 July 26th, 2008 12:23 AM
Query based on a list box ghall202 Access VBA 4 November 2nd, 2007 07:10 AM
multi-column list box values moved to 2nd list box sbmvr Access VBA 1 May 14th, 2007 01:58 PM
select box/List box alphabetic sort sasidhar79 Javascript How-To 3 November 10th, 2004 03:04 AM
Populate List Box by Combo Box Selection mmcdonal Access 2 June 15th, 2004 12:08 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.