• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Javascript Problem :( Help

hi masters of javascript! i have a little problem here. i want to apply a simple form validation on a textbox if the user failed to input any value upon clicking the submit button.

here's my code:
<html><head><script language= "javascript"> function sel(frm){var pet = frm.chkSubj;var a="<ul>";for (i=0;i<pet.length;i++) { if(pet.checked) { a+="<li>"+pet.value+"</li>"; }} a+="</ul>"; a="Your Subject is/are : "+ a;var courses = frm.cboCourse;var idx = courses.selectedIndex;var course = courses.options[idx].value;var years=frm.optYear;var ctrs;var as;for(ctrs=0;ctrs<years.length;ctrs++){if(years[ctrs].checked){as=years[ctrs].value;break;}}var nam = frm.txtname.value;document.getElementById("name").innerHTML="Name : " + nam;document.getElementById("subj").innerHTML= a;document.getElementById("year").innerHTML="Year : " + as;document.getElementById("course").innerHTML="Course : " + course;}</script></head><body><form> Name: <input type="text" name="txtname"/> <br /><br /> Course: <select name="cboCourse"> <option value="-1"></option> <option value="BSCS">BSCS</option> <option value="BSIT">BSIT</option> <option value="ComEng">ComEng</option> <option value="ComTech">ComTech</option> <option value="ComSec">ComSec</option> <option value="ACHT">ACHT</option> </select> <br /><br /> Year: <input type="radio" value="First" name="optYear" checked="checked"/>I <input type="radio" value="Second" name="optYear" />II <input type="radio" value="Third" name="optYear" />III <input type="radio" value="Fourth" name="optYear" />IV <br /><br /> Subjects: <br /> <input type="checkbox" value="CP1" name="chkSubj" />CP1 <input type="checkbox" value="DBMS" name="chkSubj" />DBMS <br /> <input type="checkbox" value="CP2" name="chkSubj" />CP2 <input type="checkbox" value="WebProg" name="chkSubj" />WebProg <br /> <input type="checkbox" value="CP3" name="chkSubj" />CP3 <input type="checkbox" value="IT Project I" name="chkSubj" />IT Project I <br /> <input type="checkbox" value="CCF" name="chkSubj" />CCF <input type="checkbox" value="IT Project II" name="chkSubj" />IT Project II <br /><br /> <input type="button" value="Process" onclick="sel(this.form)" /> <input type="reset" value="Clear" onclick ="Delete"/></form><div id="name"></div><div id="course"></div><div id="year"></div><div id="subj"></div></body></html>Here's the sample output:

and here's the asterisk or input validation should be...

Thanks for all your help!