Choose from our various pricing plans. There is a package for everyone!


Solved: Help with Javascript Form Validation

View previous topic View next topic Go down

Topic Solved Solved: Help with Javascript Form Validation

Post by mialimos on Mon Feb 10, 2014 3:50 am

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:



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!
avatar
mialimos
Member
Member

Age : 32
Posts : 3
Join date : 2014-02-01
Forum Version : PhpBB2
Reputation : 0

View user profile http://www.generatecss.com/

Back to top Go down

Topic Solved Re: Solved: Help with Javascript Form Validation

Post by Stallmp on Thu Feb 13, 2014 3:33 pm

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
avatar
Stallmp
Member
Member

Age : 23
Posts : 227
Join date : 2014-01-10
Forum Version : PunBB
Reputation : 15

View user profile

Back to top Go down

Topic Solved Re: Solved: Help with Javascript Form Validation

Post by Th1nK on Tue Apr 29, 2014 11:39 am

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.
avatar
Th1nK
Administrator
Administrator

Posts : 468
Join date : 2012-04-06
Reputation : 43

View user profile http://www.csshelp.net

Back to top Go down

Topic Solved Re: Solved: Help with Javascript Form Validation

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum