ODBiC Discussion Board

RE: Java Script and ODBIC, KenRoy, 05-03-2004

Java Script and ODBIC

by David, May 18, 2004 13:19

Here is the basic setup that you need for form validation.... In the head section is the javascript function.... you must use/have the structure of "document.form1.varible.value" to get value of non-drop down items from your entry in the form AND use the structure of document.form1.sd_code[document.form1.sd_code.selectedIndex].value; to get the value of dropdown lists. 'form1' in the structure is the name I gave the form. (See form tag). In the form tag, in addition to the name attribute, you must also have the onsubmit = "return validate()" attribute so computer will go through the javacript validation after the submit button has been pressed.(See form tag). The variable names/values inside the form tags are sent to both your javascript function (for validation) and to your whatever page you are going to "post" to. Usually I "post" to another page for actual database inserting/updating, and then give a confirmation that the desired action has been done.

<HEAD> <script> <!-- Begin

function validate() { var ee = document.form1.ee_num.value; var sdcode = document.form1.sd_code[document.form1.sd_code.selectedIndex].value;

if (document.form1.ee_num.value < 200 || document.form1.ee_num.value > 9999999 || isNaN(document.form1.ee_num.value) || document.form1.ee_num.value == '') { document.form1.ee_num.focus(); document.form1.ee_num.select(); alert('Enter a valid Employee number.') return false; } else if (sdcode == 'NONE') { alert('Please select the 2 Letter COSMOS disruption code.') return false; }

// End --> </script>

<body> <FORM name="form1" onsubmit = "return validate()" METHOD="post" ACTION="http://URL that the variables will be sent to">

<%NOTE: This is a simple text box %> <td ALIGN="MIDDLE" nowrap><b>Your Employee #:</b>  <input name="ee_num" size="7"> </TD>

<%NOTE: This is a ODBIC Dbase call %> <!--DATABASE DSN=disrupt; UID=; PWD=; FIL=MS Access;--> <!--SQL SELECT DISTINCT code_id FROM SD_Codes order by code_id--> <!-- IF $sql_status$ = -1 --> $sql_error$ <!--ENDIF--> <!--IF $row$ --> <SELECT NAME="sd_code"> <OPTION value="NONE"> </OPTION> <!--EACHROW--> <OPTION value="$code_id$">$code_id$</OPTION> <!--ENDIF--> <!--ENDROW--> </SELECT> <!--ELSE--> <!-- (no data selected) --> <!--ENDIF-->

<input TYPE="submit" value="Submit Entry"> </FORM> </HTML>


Post Your Reply:

E-mail  optional

HTTP Link: 
Link text: 

Copyright ©1997-2003, Roger Harris. All rights reserved.