Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to validate dynamic generated text fields field by field?

Status
Not open for further replies.

necta

Technical User
Mar 8, 2004
35
MY
I have a dynamic generated text fields for number input. I want to validate each field is numeric before submit it. However error occurred. I am not the sure whether the method I invoked the Sub us correct? What I have done wrong?

Code snippet:
<script language="VBSCript">
<!--
Sub subjName<%=subjNo%>" _onblur()
Dim EntryNumber
EntryNumber = window.txtNumber.value
if IsNumeric(EntryNumber) then
if EntryNumber < -1 or EntryNumber > 100 then
MsgBox ("Please enter a number between 1 and 100.")
Else
MsgBox ("Your entry was valid.")
End If
Else
MsgBox ("Please enter a numeric value.")
End if
End Sub
-->

</script>
…..
..,

<input type="text" id="txtNumber" maxlength="3" name="subjName<%=subjNo%>" value="" size="4" onblur=submit()>
 
You have some errors here as i see
First you declare an event with
Sub subjName<%=subjNo%>" _onblur() but on the line
<input type="text" id="txtNumber" maxlength="3" name="subjName<%=subjNo%>" value="" size="4" onblur=submit()> you override that event by caling Submit function... so there will be no checking by using default event unless you call the subjName<%=subjNo%>" _onblur function inside the submit function.

using your code i would make it like this
Code:
<script language="VBSCript"> 
<!--
Sub subjName<%=subjNo%>" _onblur()
 Dim EntryNumber
 Dim obj=document.all.subjName<%=subjNo%>
 EntryNumber = obj.value 
 if IsNumeric(EntryNumber) then
    if EntryNumber < -1 or EntryNumber > 100 then
      MsgBox ("Please enter a number between 1 and 100.")
      obj.focus
    Else
      MsgBox ("Your entry was valid.")
    End If
 Else
  MsgBox ("Please enter a numeric value.")
  obj.focus
 End if
End Sub 
-->

</script>
...
<input type="text" maxlength="3" name="subjName<%=subjNo%>" value="" size="4">

Anyway i'm still in doubt if this will gonna work but we could help you with ideeas if you tell us what you wanna do?

Do you have some form which generates text fields dinamicaly and you want them to validate as numeric values before submiting?

________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
Hi George,
Thanks for the reply.
Actually,I want to validate each field is numeric(marks) and then calculate the total (after the numeric fields)and average(after the 'total' field). for e.g if it has 5 numeric fields. The average will be =(total/5). If a mark is not available. The total will calculate those available(e.g: 1 numeric filed mark is unavilable). The average will =(total/4). I wonder if I could ignore the unavailable field and still get the desire total and average.
The total and average will only for viewing purpose and will not b submitted to the database.

The marks for each item will b retrieved in a report later together with total and average (calculate after marks being retrieved).

Necta
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top