|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Is there anyway to do the following:
(HTML Form) appcode: 1 deg/dip/cert field major-subject ------------------------------------------------------ row1 BSc Maths Maths row2 HSC Science Electronics row3 SSC SUBMIT button. but what happens here is that there is no check put forth....what i actually want is, if a person enters in column1 the remaining 2 column entries should become compuslory (ie. shouldnt be left NULL) let me give the above eg. now in row1, all three columsn filled, so no probs. no person enters in row2, he fills all three columns, again no probs. but... in row3 he has entered only SSC, but he does not enter the field, and major-subject column. So is there a kind of check that can be performed that once the person enters something in the first column (or say certain column), some of the other columns should be made compulsory, based on that specific (certain) column.? I am giving you an example url, which is something i want in a practical way. http://akshaysalkar.tripod.com/FormPg4.htm hope anyone can help. ak. |
|
#2
|
|||
|
|||
|
Working with the sample page, you could do something simple (and a little bloated) like:
<script type="text/javascript" language="JavaScript"> // Array with all the fields for individual rows per element var fieldArray = new Array(); fieldArray[0] ="textfield2243373207,textfield2243373386272,textfield22433733862132,textfield2243373447,textfield2243 373502,textfield22433735022" fieldArray[1] ="textfield22433732072,textfield22433733862722,textfield224337338621322,textfield22433734472,textfield 2243373512,textfield22433735023" function checkFields() { var errorString = ""; for (var i = 0; i < fieldArray.length; i++) { tmpElement = fieldArray[i].split(","); var gotBlank = 0; for (var ii = 0; ii < tmpElement.length; ii++) { tmpField = tmpElement[ii]; if (document.forms.form1.elements[tmpField].value == "") { gotBlank++; } } if (gotBlank < tmpElement.length && gotBlank > 0) { errorString += "You gotta fill out all the fields for row " + i + "n"; } } if (errorString != "") { alert(errorString); return false; } else { return true; } } </script> and make sure on your FORM you have: <form name="form1" onSubmit="return checkFields();"> This will check each row and if only some of the fields are filled in for that row it will give the error. It's not elegant but see if this is a useful base for improving on and making more robust. |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > Add entries in Form depending on previous entries? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|