Solved: Help with Javascript Form Validation
Page 1 of 1 • Share •
Solved: Help with Javascript Form Validation
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:
here's the sample output:

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

Thank you for all your help!
here's my code:
- 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[i].checked)
{
a+="<li>"+pet[i].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...

Thank you for all your help!
mialimos- Member
- Age : 32
Posts : 3
Join date : 2014-02-01
Forum Version : PhpBB2
Reputation : 0
Re: Solved: Help with Javascript Form Validation
Hello, this website is meant to help people with CSS/Javascript/HTML on Forums (Eg: Forumotion). For javascript, we also provide client side scripting. We probably can't help you with this problem unfortunately sorry.
The point of the message is:
1. There might be a huge delay in support
2. We might are unable to help you with this problem
Stay tuned
The point of the message is:
1. There might be a huge delay in support
2. We might are unable to help you with this problem
Stay tuned
Stallmp- Member
- Age : 24
Posts : 227
Join date : 2014-01-10
Forum Version : PunBB
Reputation : 15
Re: Solved: Help with Javascript Form Validation
The question(s) in this topic have been answered and the owner has been able to solve the problem. Because of this, the topic has been locked. If you have other questions, please open a new topic. |
Th1nK- Administrator
- Posts : 468
Join date : 2012-04-06
Reputation : 43
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum