Link to home
Create AccountLog in
Avatar of David Megnin
David MegninFlag for United States of America

asked on

JavaScript to calculate some wages and hours in an ASP.Net web form.

I have a web form for entering OJT training hours and wages.  There are four TextBoxes for entering the number of weeks, hours per week, hourly wage and the percent of the wage paid.

I'm currently using a button to execute three calculations to set the values of three labels:
btnRecalculate:
'Training Hours = Number of Weeks * Hours per Week:
lblNumberTrainingHours.Text = LengthTrainingWeeks.Text * HoursPerWeek.Text

'Hourly Rate = Wage * Percent (e.g. $25.00 * 100% = $25.00):
lblTrainingPaymentHourlyRate.Text = String.Format("{0:c}", (TraineeEntryWage.Text * (TrainingPaymentPercent.Text / 100)))

'Max Amount = Hourly Rate * Training Hours
lblMaxAmountReimbursed.Text = String.Format("{0:c}", (lblTrainingPaymentHourlyRate.Text * lblNumberTrainingHours.Text))

Open in new window


I don't want to rely on the person remembering to click the button, so I want the calculations done in "real time".  I tried using the OnChange event of the TextBoxes, but that was crappy and I don't thing an UpdatePanel is the answer either.

I think JavaScript is the answer, but I don't know how to write the script.  I'm learning to modify existing scripts but don't know it well enough to craft this by myself.  Could someone help me with it?  Thank you very much!!

Here's the asp.net markup of the textboxes, labels and button:
<tr>
			<td class="L">Length of Training<br />(in weeks):</td>
			<td class="R" bgcolor="#FFFFCC">
				<asp:TextBox ID="LengthTrainingWeeks" runat="server" Width="35px" onkeypress="return num(this)" TabIndex="5300"/>
			</td>
			<td class="L" colspan="2">Hours Per Week:</td>
			<td class="R" colspan="2" bgcolor="#FFFFCC">
				<asp:TextBox ID="HoursPerWeek" runat="server" Width="35px" onkeypress="return num(this)" TabIndex="5400"/>
			</td>
		</tr>
		<tr>
			<td class="L">Trainee&#39;s Entry Wage:</td>
			<td class="R" bgcolor="#99CCFF">
			&#36;<asp:TextBox ID="TraineeEntryWage" runat="server" Width="40px" onkeypress="return num(this)" TabIndex="5500"/>
			</td>
			<td class="L" colspan="2">Training Payment %:</td>
			<td class="R" colspan="2" bgcolor="#99CCFF">
				<asp:TextBox ID="TrainingPaymentPercent" runat="server" Width="35px" onkeypress="return num(this)" TabIndex="5600" style="text-align:right;" />&#37;</td>
		</tr>
		<tr>
			<td class="L">Training Payment<br />
				as an Hourly Rate:</td>
			<td class="R" bgcolor="#99CCFF">
				<asp:Label ID="lblTrainingPaymentHourlyRate" runat="server" BackColor="#CCFFCC" Text="0" /></td>
			<td class="L" colspan="2">Number of Training Hours:</td>
			<td class="R" colspan="2" bgcolor="#FFFFCC">
				<asp:Label ID="lblNumberTrainingHours" runat="server" BackColor="#CCFFCC" Text="0" /></td>
		</tr>
		<tr>
			<td class="L">Maximum Amount<br />
				to be Reimbursed:</td>
			<td class="R">
				<asp:Label ID="lblMaxAmountReimbursed" runat="server" BackColor="#CCFFCC" />
				<asp:Button ID="btnRecalculate" runat="server" Text="Calc" TabIndex="5700" />
			</td>

Open in new window

Avatar of crisco96
crisco96
Flag of United States of America image

in each textbox add onkeyup="UpdateTotal()" then include the javascript below
<script type="text/javascript">
   function isNumeric(val)
   {
     return !isNaN(val) && val != "";
   }

   function UpdateTotal()
   {
      var numWeeks = document.getElementById("<%=LengthTrainingWeeks.ClientID%>");
      var hoursPerWeek = document.getElementById("<%=HoursPerWeek.ClientID%>");
      var traineeWage = document.getElementById("<%=TraineeEntryWage.ClientID%>");
      var trainingPaymentPercent = document.getElementById("<%=TrainingPaymentPercent.ClientID%>");

      if(isNumeric(numWeeks) || isNumeric(hoursPerWeek) || isNumeric(traineeWage) || isNumeric(trainingPaymentPercent)

      //not sure how you are going to do the calculations so modify this area accordingly
      var paymentHourlyRate = traineeWage * trainingPaymentPercent/100.0
      var numTrainingHours = numWeeks * hoursPerWeek;
      var maxReimbursed = paymentHourlyRate * numTrainingHours;

      document.getElementById("<%=lblTrainingPaymentHourlyRate.ClientID%>").innerHTML = paymentHourlyRate;
      document.getElementById("<%=lblNumberTrainingHours.ClientID%>").innerHTML = numTrainingHours;
      document.getElementById("<%=lblMaxAmountReimbursed.ClientID%>").innerHTML = maxReimbursed;
   }
</script>

Open in new window

Avatar of David Megnin

ASKER

I'm not sure what caused this.
Is the <% ...%> necessary in the getElementById() ?  I don't remember what <%...%> does.

Server Error in '/' Application.
--------------------------------------------------------------------------------

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace:


[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
   System.Web.UI.ControlCollection.Add(Control child) +8677431
   AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) in C:\Users\swalther\Projects\ACT\Releases\30512.1\AjaxControlToolkitSource\AjaxControlToolkit\ExtenderBase\ScriptObjectBuilder.cs:303
   AjaxControlToolkit.ExtenderControlBase.OnLoad(EventArgs e) in C:\Users\swalther\Projects\ACT\Releases\30512.1\AjaxControlToolkitSource\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs:307
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082
Are you dynamically adding controls to the page? The reason that's happening is because I am using .net script blocks to determine the html ids of the controls.
I'm not dynamically adding any controls to the page.

I removed the <%..%> stuff and it updates dynamically but I get "NaN" and "undefined" in the labels.  I may only need to cast the values as numbers to fix that. ?

   function UpdateTotal()  
   {  
      var numWeeks = document.getElementById("LengthTrainingWeeks");  
      var hoursPerWeek = document.getElementById("HoursPerWeek");  
      var traineeWage = document.getElementById("TraineeEntryWage");  
      var trainingPaymentPercent = document.getElementById("TrainingPaymentPercent");  
  
      if(isNumeric(numWeeks) || isNumeric(hoursPerWeek) || isNumeric(traineeWage) || isNumeric(trainingPaymentPercent)) 
  
      //not sure how you are going to do the calculations so modify this area accordingly  
      var paymentHourlyRate = traineeWage * (trainingPaymentPercent/100.0);
      var numTrainingHours = numWeeks * hoursPerWeek;  
      var maxReimbursed = paymentHourlyRate * numTrainingHours;  
  
      document.getElementById("lblTrainingPaymentHourlyRate").innerHTML = paymentHourlyRate;  
      document.getElementById("lblNumberTrainingHours").innerHTML = numTrainingHours;  
      document.getElementById("lblMaxAmountReimbursed").innerHTML = maxReimbursed;  
   }  

Open in new window

SOLUTION
Avatar of Proculopsis
Proculopsis

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Proculopsis, that looks like a nice technique, but a little more advanced than my ability to even modify it though, as I don't understand exactly how that eventChange() function works.

getElementById("TextBox1.Text") is about as advanced as I can understand right now.  ;-)

I think this just needs a slight tweak.
right now lblTrainingPaymentHourlyRate is displaying "undefined" and "lblNumberTrainingHours" and "lblMaxAmountReimbursed" both say "NaN".
<script type="text/javascript">  
   function isNumeric(val)  
   {  
     return !isNaN(val) && val != "";  
   }  
  

   function UpdateTotal()    
   {    
      var numWeeks = document.getElementById("LengthTrainingWeeks");    
      var hoursPerWeek = document.getElementById("HoursPerWeek");    
      var traineeWage = document.getElementById("TraineeEntryWage");    
      var trainingPaymentPercent = document.getElementById("TrainingPaymentPercent");    
    
      if(isNumeric(numWeeks) || isNumeric(hoursPerWeek) || isNumeric(traineeWage) || isNumeric(trainingPaymentPercent))   
    
      //not sure how you are going to do the calculations so modify this area accordingly    
      var paymentHourlyRate = traineeWage * (trainingPaymentPercent/100.0);  
      var numTrainingHours = numWeeks * hoursPerWeek;    
      var maxReimbursed = paymentHourlyRate * numTrainingHours;    
    
      document.getElementById("lblTrainingPaymentHourlyRate").innerHTML = paymentHourlyRate;    
      document.getElementById("lblNumberTrainingHours").innerHTML = numTrainingHours;    
      document.getElementById("lblMaxAmountReimbursed").innerHTML = maxReimbursed;    
   }  
</script>

Open in new window

I tried adding adding Number(...), but it made no difference:
   function UpdateTotal()  
   {  
      var numWeeks = document.getElementById("LengthTrainingWeeks");  
      var hoursPerWeek = document.getElementById("HoursPerWeek");  
      var traineeWage = document.getElementById("TraineeEntryWage");
      var trainingPaymentPercent = document.getElementById("TrainingPaymentPercent");
      numWeeks = Number(numWeeks)
      hoursPerWeek = Number(hoursPerWeek)
      traineeWage = Number(traineeWage)
      trainingPaymentPercent=Number(trainingPaymentPercent)
  
      if(isNumeric(numWeeks) || isNumeric(hoursPerWeek) || isNumeric(traineeWage) || isNumeric(trainingPaymentPercent)) 

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Oh and the explination for the <%=...%>.  That is telling the asp.net parser to look to the server side to find the actual html id of the control. When you view the source of the page the <input sometimes has a different id than the one you specified (especially if you're using a master page). You shouldn't get an error when using that unless you're adding or removing controls in the code behind, can you please post your code behind?
Ahhh, that made all the difference.  ;-)  Works great! Thank you.
Pardon the comments.  Here is my code behind if you still want to see it.
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls

Partial Public Class _Default
    Inherits System.Web.UI.Page

    Dim iUserName As String = "UserName" ' Environment.UserName

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Const STR_PleaseWait As String = "Please Wait"
        lblTitle.Text = STR_PleaseWait
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'iUserName = Right(Request.ServerVariables("AUTH_USER"), (Request.ServerVariables("AUTH_USER").Length - 5))  'Remove the five characters: "BETA\"
        'iUserName = Request.ServerVariables("AUTH_USER")
        iUserName = Environment.UserName.ToString
        'Response.Write("UserName: " & iUserName)
        ' If Not IsPostBack Then
        '######################################################################################################
        '' Read sql server connection string from web.config file
        'Dim sConstr As String = ConfigurationManager.ConnectionStrings("OJTConnectionString").ConnectionString
        'Dim Conn As New SqlConnection(sConstr)
        'Dim dt As New DataTable("tbl")

        'Using Conn
        '    Conn.Open()
        '    Dim comm As New SqlCommand("SELECT Code,Description FROM NAICS ORDER BY Description ASC", Conn)
        '    Dim da As New SqlDataAdapter(comm)
        '    da.Fill(dt)
        'End Using

        'ddlNAICS.DataSource = Nothing
        'ddlNAICS.DataTextField = "Description"
        'ddlNAICS.DataValueField = "Code"
        'ddlNAICS.DataBind()
        'End If
    End Sub

    Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete
        Const STR_OJTDataInputForm As String = "OJT Data Input Form"
        lblTitle.Text = STR_OJTDataInputForm
    End Sub

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        ddlNAICSDescription.Items.Clear()

        Dim sSql As String = "SELECT Description, Code FROM NAICS WHERE Description LIKE '%" & txtSearch.Text & "%' ORDER BY Description ASC"
        Dim cmd As New SqlCommand(sSql, New SqlConnection(ConfigurationManager.ConnectionStrings("OJTConnectionString").ConnectionString))
        'cmd.Parameters.Add("@SearchNAIC", SqlDbType.VarChar).Value = txtSearch.Text  'I replaced the @SearchNAIC parameter with txtSearch.Text

        cmd.Connection.Open()

        Dim drNAIC As SqlDataReader
        drNAIC = cmd.ExecuteReader()
        drNAIC.Read()
        'Dim ds As New DataSet
        'ds.ReadXml(MapPath("NAICS.xml"))

        ddlNAICSDescription.DataSource = drNAIC           'ds
        ddlNAICSDescription.DataTextField = "Description"
        ddlNAICSDescription.DataValueField = "Code"
        ddlNAICSDescription.DataBind()

        cmd.Connection.Close()
        cmd.Connection.Dispose()

    End Sub

    Protected Sub ddlNAICS_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlNAICSDescription.SelectedIndexChanged
        lblNAICSCode.Text = ddlNAICSDescription.SelectedValue.ToString
    End Sub

    Protected Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitButton.Click
        Call SendDataToEmployers()

    End Sub

    Protected Sub CancelButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CancelButton.Click
        Response.Redirect("default.aspx")
    End Sub

    'Protected Sub TrainingPaymentPercent_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TrainingPaymentPercent.TextChanged
    '    'Call UpdateTotals()
    'End Sub

    'Protected Sub HoursPerWeek_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles HoursPerWeek.TextChanged
    '    'Call UpdateTotals()  ''
    'End Sub

    Protected Sub btnRecalculate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRecalculate.Click
        If LengthTrainingWeeks.Text > "0" And HoursPerWeek.Text > "0" And TraineeEntryWage.Text > "0" And TrainingPaymentPercent.Text > "0" Then
            Call UpdateTotals()
        Else
            lblMaxAmountReimbursed.Text = "No Value"
            lblTrainingPaymentHourlyRate.Text = "No Value"
            lblNumberTrainingHours.Text = "No Value"
        End If
    End Sub

    Protected Sub UpdateTotals()
        ''##################################################################################From txtTrainingPaymentPercent.TextChanged
        'Dim Wage, Percent, Rate As Double
        'If Not Double.TryParse(txtTraineeEntryWage.Text, Wage) Then
        '    ' TryParse failed. Set Wage equal to zero
        '    Wage = 0
        'End If
        'If Not Double.TryParse(txtTrainingPaymentPercent.Text, Percent) Then
        '    Percent = 0
        'End If

        'Rate = Wage * Percent / 100

        'lblTrainingPaymentHourlyRate.Text = String.Format("{0:c}", Rate) ' txtTraineeEntryWage.Text * txtTrainingPaymentPercent.Text / 100

        ''##################################################################################From txtHoursPerWeek.TextChanged
        'Dim tWeeks, tHours, tRate, tNumber, TrainingHours, AmountReimbursed As Double
        'If Not Double.TryParse(txtLengthTrainingWeeks.Text, tWeeks) Then
        '    tWeeks = 0
        'End If
        'If Not Double.TryParse(txtHoursPerWeek.Text, tHours) Then
        '    tHours = 0
        'End If
        'If Not Double.TryParse(lblTrainingPaymentHourlyRate.Text, tRate) Then
        '    tRate = 1
        'End If
        'If Not Double.TryParse(lblNumberTrainingHours.Text, tNumber) Then
        '    tNumber = 9999
        'End If

        'TrainingHours = tWeeks * tHours
        'AmountReimbursed = tRate * tNumber

        'lblNumberTrainingHours.Text = TrainingHours.ToString ' tHours * tWeeks ' txtLengthTrainingWeeks.Text * txtHoursPerWeek.Text
        'lblMaxAmountReimbursed.Text = String.Format("{0:c}", AmountReimbursed) '.ToString("{0:c}") ' tRate * tNumber ' lblTrainingPaymentHourlyRate.Text * lblNumberTrainingHours.Text
        ''##################################################################################

        lblNumberTrainingHours.Text = LengthTrainingWeeks.Text * HoursPerWeek.Text
        lblTrainingPaymentHourlyRate.Text = String.Format("{0:c}", (TraineeEntryWage.Text * (TrainingPaymentPercent.Text / 100)))
        lblMaxAmountReimbursed.Text = String.Format("{0:c}", (lblTrainingPaymentHourlyRate.Text * lblNumberTrainingHours.Text))

    End Sub

    Protected Sub SendDataToEmployers()

        Dim varBrowser As String = ""
        Dim varIPAddress As String = ""

        varBrowser = Request.Browser.Browser.ToString & " " & Request.Browser.MajorVersion
        varIPAddress = Request.UserHostAddress.ToString

        Dim DBConn As New SqlConnection(ConfigurationManager.ConnectionStrings("OJTConnectionString").ConnectionString)
        Dim DBCmd As New SqlCommand
        Dim sql As String
        sql = "IF (SELECT COUNT(TaxID) FROM Employers WHERE (TaxID = @TaxID)) > 0  SELECT -1 as error  FROM Employers ELSE BEGIN SET NOCOUNT ON; INSERT INTO Employers (JD_FirstName, JD_LastName, CompanyName, NAICSDescription, NAICSCode, JobTitle, JobDescription, PrincipalsName, NumberEmployees, TaxID, MinorityBusiness, Address, City, State, Zip, Telephone, Fax, BusinessType, YearsInBroward, RegisteredInSunbiz, ApprenticeshipProgramsAvailable, WorkersCompNumber, OccupationalLicenseNumber, SeasonalEmployment, EntryLevelPositions, TraineeRatio, WorkingConditions, SafetyProcedures, PaidHolidays, Fringes, AdequateRetentionHistory, IndependentContractor, AccessToResources, RecommendContract, CollectiveBargainingUnit, BargainingAgentAndOccupation, DateSubmittedToCBR, DateReceivedByCBR, DateSubmittedToLegal, DateEffective, DateAgreementActiveUntil, DateReturnedToCBRFromExec, DateTrainingPlanSigned, DateScannedToS_Drive, AgreementNumber, OJTTrainingPlanNumber, ParticipantFirstName, ParticipantLastName, SSN4, SVP, DateTrainingStart, DateTrainingEnd, LengthOfTraining, HoursPerWeek, TraineesEntryWage, TrainingPaymentPercent, TrainingPaymentHourlyRate, NumberOfTrainingHours, MaximumAmountToBeReimbursed, RetentionPeriod, WIASuccessCoach, DateInvoiceReceived, DateInvoicePaid, AmountPaid, SubmittedBy, DateSubmitted, IPAddress, ClientBrowser) VALUES (@JD_FirstName, @JD_LastName, @CompanyName, @NAICSDescription, @NAICSCode, @JobTitle, @JobDescription, @PrincipalsName, @NumberEmployees, @TaxID, @MinorityBusiness, @Address, @City, @State, @Zip, @Telephone, @Fax, @BusinessType, @YearsInBroward, @RegisteredInSunbiz, @ApprenticeshipProgramsAvailable, @WorkersCompNumber, @OccupationalLicenseNumber, @SeasonalEmployment, @EntryLevelPositions, @TraineeRatio, @WorkingConditions, @SafetyProcedures, @PaidHolidays, @Fringes, @AdequateRetentionHistory, @IndependentContractor, @AccessToResources, @RecommendContract, @CollectiveBargainingUnit, @BargainingAgentAndOccupation, @DateSubmittedToCBR, @DateReceivedByCBR, @DateSubmittedToLegal, @DateEffective, @DateAgreementActiveUntil, @DateReturnedToCBRFromExec, @DateTrainingPlanSigned, @DateScannedToS_Drive, @AgreementNumber, @OJTTrainingPlanNumber, @ParticipantFirstName, @ParticipantLastName, @SSN4, @SVP, @DateTrainingStart, @DateTrainingEnd, @LengthOfTraining, @HoursPerWeek, @TraineesEntryWage, @TrainingPaymentPercent, @TrainingPaymentHourlyRate, @NumberOfTrainingHours, @MaximumAmountToBeReimbursed, @RetentionPeriod, @WIASuccessCoach, @DateInvoiceReceived, @DateInvoicePaid, @AmountPaid, @SubmittedBy, GetDate(), @IPAddress, @ClientBrowser); Select SCOPE_IDENTITY() END"
        DBConn.Open()

        Try
            'Add Insert Statement 
            DBCmd = New SqlCommand(sql, DBConn)

            'Add Database Parameters
            DBCmd.Parameters.Add("@JD_FirstName", SqlDbType.VarChar).Value = JD_FirstName.Text
            DBCmd.Parameters.Add("@JD_LastName", SqlDbType.VarChar).Value = JD_LastName.Text
            DBCmd.Parameters.Add("@CompanyName", SqlDbType.VarChar).Value = CompanyName.Text
            DBCmd.Parameters.Add("@NAICSDescription", SqlDbType.VarChar).Value = ddlNAICSDescription.SelectedValue
            DBCmd.Parameters.Add("@NAICSCode", SqlDbType.VarChar).Value = lblNAICSCode.Text
            DBCmd.Parameters.Add("@JobTitle", SqlDbType.VarChar).Value = JobTitle.Text
            DBCmd.Parameters.Add("@JobDescription", SqlDbType.VarChar).Value = JobDescription.Text
            DBCmd.Parameters.Add("@PrincipalsName", SqlDbType.VarChar).Value = PrincipalsName.Text
            DBCmd.Parameters.Add("@NumberEmployees", SqlDbType.VarChar).Value = ddlNumberEmployees.SelectedValue
            DBCmd.Parameters.Add("@TaxID", SqlDbType.VarChar).Value = TaxID.Text
            DBCmd.Parameters.Add("@MinorityBusiness", SqlDbType.VarChar).Value = radMinorityBusiness.SelectedValue
            DBCmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = Address.Text
            DBCmd.Parameters.Add("@City", SqlDbType.VarChar).Value = City.Text
            DBCmd.Parameters.Add("@State", SqlDbType.VarChar).Value = State.Text
            DBCmd.Parameters.Add("@Zip", SqlDbType.VarChar).Value = Zip.Text
            DBCmd.Parameters.Add("@Telephone", SqlDbType.VarChar).Value = Telephone.Text
            DBCmd.Parameters.Add("@Fax", SqlDbType.VarChar).Value = Fax.Text
            DBCmd.Parameters.Add("@BusinessType", SqlDbType.VarChar).Value = ddlBusinessType.SelectedValue
            DBCmd.Parameters.Add("@YearsInBroward", SqlDbType.VarChar).Value = YearsInBroward.Text
            DBCmd.Parameters.Add("@RegisteredInSunbiz", SqlDbType.VarChar).Value = radRegisteredSunbiz.SelectedValue
            DBCmd.Parameters.Add("@ApprenticeshipProgramsAvailable", SqlDbType.VarChar).Value = radApprentProgAvail.SelectedValue
            DBCmd.Parameters.Add("@WorkersCompNumber", SqlDbType.VarChar).Value = WorkersCompNo.Text
            DBCmd.Parameters.Add("@OccupationalLicenseNumber", SqlDbType.VarChar).Value = OccupationalLicenseNo.Text
            DBCmd.Parameters.Add("@SeasonalEmployment", SqlDbType.VarChar).Value = radSeasonalEmployment.SelectedValue
            DBCmd.Parameters.Add("@EntryLevelPositions", SqlDbType.VarChar).Value = EntryPositions.Text
            DBCmd.Parameters.Add("@TraineeRatio", SqlDbType.VarChar).Value = TraineeRatio1.Text & ":" & TraineeRatio2.Text
            DBCmd.Parameters.Add("@WorkingConditions", SqlDbType.VarChar).Value = ddlWorkingConditions.SelectedValue
            DBCmd.Parameters.Add("@SafetyProcedures", SqlDbType.VarChar).Value = radSafetyProcedures.SelectedValue
            DBCmd.Parameters.Add("@PaidHolidays", SqlDbType.VarChar).Value = PaidHolidays.Text
            DBCmd.Parameters.Add("@Fringes", SqlDbType.VarChar).Value = Fringes.Text
            DBCmd.Parameters.Add("@AdequateRetentionHistory", SqlDbType.VarChar).Value = radRetentionHistory.SelectedValue
            DBCmd.Parameters.Add("@IndependentContractor", SqlDbType.VarChar).Value = radIndepContractor.SelectedValue
            DBCmd.Parameters.Add("@AccessToResources", SqlDbType.VarChar).Value = radAccessToEquipment.SelectedValue
            DBCmd.Parameters.Add("@RecommendContract", SqlDbType.VarChar).Value = radRecommendPursuit.SelectedValue
            DBCmd.Parameters.Add("@CollectiveBargainingUnit", SqlDbType.VarChar).Value = radCollectiveBargainingUnit.SelectedValue
            DBCmd.Parameters.Add("@BargainingAgentAndOccupation", SqlDbType.VarChar).Value = ListBargainingAgent.Text
            DBCmd.Parameters.Add("@DateSubmittedToCBR", SqlDbType.VarChar).Value = SubmittedCBRDate.Text
            DBCmd.Parameters.Add("@DateReceivedByCBR", SqlDbType.VarChar).Value = ReceivedCBRDate.Text
            DBCmd.Parameters.Add("@DateSubmittedToLegal", SqlDbType.VarChar).Value = SubmitLegalDate.Text
            DBCmd.Parameters.Add("@DateEffective", SqlDbType.VarChar).Value = EffectiveDate.Text
            DBCmd.Parameters.Add("@DateAgreementActiveUntil", SqlDbType.VarChar).Value = ActiveUntilDate.Text
            DBCmd.Parameters.Add("@DateReturnedToCBRFromExec", SqlDbType.VarChar).Value = ReturnedToCBRDate.Text
            DBCmd.Parameters.Add("@DateTrainingPlanSigned", SqlDbType.VarChar).Value = TrainingPlanSignedDate.Text
            DBCmd.Parameters.Add("@DateScannedToS_Drive", SqlDbType.VarChar).Value = ScannedToStorageDate.Text
            DBCmd.Parameters.Add("@AgreementNumber", SqlDbType.VarChar).Value = AgreementNumber.Text
            DBCmd.Parameters.Add("@OJTTrainingPlanNumber", SqlDbType.VarChar).Value = OJTTrainingPlanNumber.Text
            DBCmd.Parameters.Add("@ParticipantFirstName", SqlDbType.VarChar).Value = ParticipantFirstName.Text
            DBCmd.Parameters.Add("@ParticipantLastName", SqlDbType.VarChar).Value = ParticipantLastName.Text
            DBCmd.Parameters.Add("@SSN4", SqlDbType.VarChar).Value = SSN4.Text
            DBCmd.Parameters.Add("@SVP", SqlDbType.VarChar).Value = SVP.Text
            DBCmd.Parameters.Add("@DateTrainingStart", SqlDbType.VarChar).Value = TrainingStartDate.Text
            DBCmd.Parameters.Add("@DateTrainingEnd", SqlDbType.VarChar).Value = TrainingEndDate.Text
            DBCmd.Parameters.Add("@LengthOfTraining", SqlDbType.VarChar).Value = LengthTrainingWeeks.Text
            DBCmd.Parameters.Add("@HoursPerWeek", SqlDbType.VarChar).Value = HoursPerWeek.Text
            DBCmd.Parameters.Add("@TraineesEntryWage", SqlDbType.VarChar).Value = TraineeEntryWage.Text
            DBCmd.Parameters.Add("@TrainingPaymentPercent", SqlDbType.VarChar).Value = TrainingPaymentPercent.Text
            DBCmd.Parameters.Add("@TrainingPaymentHourlyRate", SqlDbType.VarChar).Value = lblTrainingPaymentHourlyRate.Text
            DBCmd.Parameters.Add("@NumberOfTrainingHours", SqlDbType.VarChar).Value = lblNumberTrainingHours.Text
            DBCmd.Parameters.Add("@MaximumAmountToBeReimbursed", SqlDbType.VarChar).Value = lblMaxAmountReimbursed.Text
            DBCmd.Parameters.Add("@RetentionPeriod", SqlDbType.VarChar).Value = radRetentionPeriod.SelectedValue
            DBCmd.Parameters.Add("@WIASuccessCoach", SqlDbType.VarChar).Value = WIASuccessCoach.Text
            DBCmd.Parameters.Add("@DateInvoiceReceived", SqlDbType.VarChar).Value = InvoiceReceivedDate.Text
            DBCmd.Parameters.Add("@DateInvoicePaid", SqlDbType.VarChar).Value = InvoicePaidDate.Text
            DBCmd.Parameters.Add("@AmountPaid", SqlDbType.VarChar).Value = AmountPaid.Text
            DBCmd.Parameters.Add("@SubmittedBy", SqlDbType.VarChar).Value = iUserName
            DBCmd.Parameters.Add("@IPAddress", SqlDbType.VarChar).Value = varIPAddress.ToString
            DBCmd.Parameters.Add("@ClientBrowser", SqlDbType.VarChar).Value = varBrowser.ToString

            Dim priKey As Integer = DBCmd.ExecuteScalar()
            If priKey < 0 Then
                'Server.Transfer("ApplicantDup.aspx")
                Response.Redirect("Employer_Dupe.aspx")
            Else
                Session("eKey") = priKey
            End If

        Catch exp As Exception
            Response.Write(exp)
        End Try
        'Close Database connection 
        DBCmd.Dispose()
        DBConn.Close()
        DBConn = Nothing

    End Sub

    '' #### This is just to list all the controls on the page so I can write the ADO DBCmd.Parameters.Add lines. ####
    'Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    '    IterateControls(Me)
    'End Sub

    'Private Sub IterateControls(ByVal control As Control)
    '    For Each c As Control In control.Controls
    '        If TypeOf c Is TextBox _
    '        Or TypeOf c Is RadioButton _
    '        Or TypeOf c Is RadioButtonList _
    '        Or TypeOf c Is Label _
    '        Or TypeOf c Is DropDownList _
    '        Or TypeOf c Is CheckBox _
    '        Or TypeOf c Is CheckBoxList Then
    '            '            Or TypeOf c Is Button _
    '            Response.Write(c.ID.ToString & "<br />")
    '        End If
    '        If c.Controls.Count > 0 Then
    '            IterateControls(c)
    '        End If
    '    Next
    'End Sub
End Class

Open in new window

In another project I also had a problem where the code did not seem to want to function when the <%=...%> markers were there.  With them removed it seems to work fine.  I'm not using Master Pages though.
Thanks again.  I'm really starting to like JavaScript for things that don't need to make yet another round trip to the server.  This was very nice.
Is it possible to format the value in the label so it displays like $27.00 or $4,800.00 instead of 27 and 4800?
Well, since I found a couple of functions that seem to work pretty well and in case anyone else can benefit from it here are the two functions I found, CurrencyFormatted() and CommaFormatted() added to the rest of the code provided here by crisco96:

The currency functions are implemented in the first, second and fourth of these lines:
      var maxReimbursed = CurrencyFormatted(paymentHourlyRate * numTrainingHours);  
 
      document.getElementById("lblTrainingPaymentHourlyRate").innerHTML = "$" + CurrencyFormatted(paymentHourlyRate);
      document.getElementById("lblNumberTrainingHours").innerHTML = numTrainingHours;
      document.getElementById("lblMaxAmountReimbursed").innerHTML = "$" + CommaFormatted(maxReimbursed);  

<script type="text/javascript">  
   function isNumeric(val)  
   {  
     return !isNaN(val) && val != "";  
   }  
  
   function UpdateTotal()  
   {  
      var numWeeks = document.getElementById("LengthTrainingWeeks").value;  
      var hoursPerWeek = document.getElementById("HoursPerWeek").value;  
      var traineeWage = document.getElementById("TraineeEntryWage").value;
      var trainingPaymentPercent = document.getElementById("TrainingPaymentPercent").value;
  
      if(isNumeric(numWeeks) || isNumeric(hoursPerWeek) || isNumeric(traineeWage) || isNumeric(trainingPaymentPercent)) 
  
      //not sure how you are going to do the calculations so modify this area accordingly  
      var paymentHourlyRate = traineeWage * (trainingPaymentPercent / 100);
      var numTrainingHours = numWeeks * hoursPerWeek;
      var maxReimbursed = CurrencyFormatted(paymentHourlyRate * numTrainingHours);  
  
      document.getElementById("lblTrainingPaymentHourlyRate").innerHTML = "$" + CurrencyFormatted(paymentHourlyRate);
      document.getElementById("lblNumberTrainingHours").innerHTML = numTrainingHours;
      document.getElementById("lblMaxAmountReimbursed").innerHTML = "$" + CommaFormatted(maxReimbursed);  
   }  
</script>
<script type="text/javascript">
	function CurrencyFormatted(amount) {
		var i = parseFloat(amount);
		if (isNaN(i)) { i = 0.00; }
		var minus = '';
		if (i < 0) { minus = '-'; }
		i = Math.abs(i);
		i = parseInt((i + .005) * 100);
		i = i / 100;
		s = new String(i);
		if (s.indexOf('.') < 0) { s += '.00'; }
		if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
		s = minus + s;
		return s;
	}
	// end of function CurrencyFormatted()
</script>

<script type="text/javascript">
	function CommaFormatted(amount) {
		var delimiter = ","; // replace comma if desired
		var a = amount.split('.', 2)
		var d = a[1];
		var i = parseInt(a[0]);
		if (isNaN(i)) { return ''; }
		var minus = '';
		if (i < 0) { minus = '-'; }
		i = Math.abs(i);
		var n = new String(i);
		var a = [];
		while (n.length > 3) {
			var nn = n.substr(n.length - 3);
			a.unshift(nn);
			n = n.substr(0, n.length - 3);
		}
		if (n.length > 0) { a.unshift(n); }
		n = a.join(delimiter);
		if (d.length < 1) { amount = n; }
		else { amount = n + '.' + d; }
		amount = minus + amount;
		return amount;
	}
	// end of function CommaFormatted()
</script>

Open in new window

Of course having the extra "$" and comma characters actually in the value instead of just using String.Format("{0:c}", value to format the value for display only, breaks the SQL Insert since the SQL field is expecting a double not a string.  ;-(