Results 1 to 3 of 3

Thread: Using Javascript to Validate Dynamically created HTML Forms

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2001
    Location
    Fredericton, NB, Canada
    Posts
    85

    Using Javascript to Validate Dynamically created HTML Forms

    The code below creates a form based on the users assigned to a course, therefore it is dynamic and to make each name for the Text Box that contains there score I have to append the user's id. How do I maneuver through the text boxes with JS if I don't know the names o fhte elements???

    Code:
    	if isarray(arrStudents) then
    		fltScore = ""
    		
    		for i = 0 to ubound(arrStudents,2)
    			IF Application("RDBMS") = "ORACLE" THEN
    				rs.Open "SELECT student_score/possible_score*100 FROM assessment_report WHERE student_id = " & arrStudents(0,i) & " AND container_id = " & request("session") & " AND testinstance = 1"
    			ELSE
    				rs.Open "SELECT CAST(student_score AS DECIMAL) / CAST(possible_score AS DECIMAL) *100 FROM assessment_report WHERE student_id = " & arrStudents(0,i) & " AND container_id = " & request("session") & " AND testinstance = 1"
    			END IF
    			
    			if rs.EOF then
    				fltScore = 0
    			else
    				fltScore = rs(0)
    			end if
    			
    			rs.close
    			
    			Response.Write "<tr><td>" & arrStudents(1,i) & " " & arrStudents(2,i) & "</td>"
    %>
    				<td><input name="txtScore<%=arrStudents(0,i)%>" value="<%=fltScore%>" size="4" onchange="javascript:if (isNaN(parseFloat(this.value))==true){alert('<%=strNOTANUMBER%>');this.value='';this.focus();}"></td><td></td></tr>
    <%
    		next
    	else
    		Response.Write "<td colspan=2>" & strNOSTUDENTS & "</td></tr>"
    	end if

  2. #2
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    how about that!

    Code:
    <script language="JavaScript">
    function cycle() {
        var answer = '';
        for (var i = 0; i<document.formName.elements.length; i++) {
            if ((document.formName.elements[i].name.indexOf('Text') > -1)) {
               	if(document.formName.elements[i].value.length<0){
    			alert('Your missing some info');
    			document.formName.elements[i].select();
    			document.formName.elements[i].focus(); 
    			break();          	
               	}
            }
        }
    }
    </script>

  3. #3
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    'Course, you could always do something like... oh... I don't know...

    DYNAMICLY CREATE THE JAVASCRIPT, TOO!
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width