CMR COLLEGE OF ENGINEERING & TECHNOLOGY
Kandlakoya, Medchal Road, Hyderabad — 501401
Application Form for Admission to Category ‘B’ Seats
Form completion: 0%
`;
rankConditional.style.display = 'block';
} else if(val === 'EAPCET'){
rankFields.innerHTML = `
`;
rankConditional.style.display = 'block';
} else if(val === 'OTHER'){
rankFields.innerHTML = `
`;
rankConditional.style.display = 'block';
} else {
rankConditional.style.display = 'none';
}
updateProgress();
}
examType.addEventListener('change', buildRankField);
/* ---------- Dynamic marks rows ---------- */
const marksBody = document.getElementById('marksBody');
const addRowBtn = document.getElementById('addRowBtn');
let rowCount = 0;
function addMarksRow(prefill){
rowCount++;
const id = 'row' + rowCount;
const tr = document.createElement('tr');
tr.id = id;
tr.innerHTML = `
|
|
|
|
0.00 |
|
`;
marksBody.appendChild(tr);
const total = tr.querySelector('.total');
const obtained = tr.querySelector('.obtained');
const pctCell = tr.querySelector('.pct-cell');
const removeBtn = tr.querySelector('.row-remove');
function recalcRow(){
const t = parseFloat(total.value);
const o = parseFloat(obtained.value);
if(t > 0 && o >= 0){
pctCell.textContent = ((o/t)*100).toFixed(2);
} else {
pctCell.textContent = '0.00';
}
recalcAggregate();
}
total.addEventListener('input', recalcRow);
obtained.addEventListener('input', recalcRow);
removeBtn.addEventListener('click', ()=>{
if(marksBody.children.length <= 1){
showToast('At least one marks row is required.');
return;
}
tr.remove();
recalcAggregate();
});
}
function recalcAggregate(){
let totalSum = 0, obtainedSum = 0;
marksBody.querySelectorAll('tr').forEach(tr=>{
const t = parseFloat(tr.querySelector('.total').value) || 0;
const o = parseFloat(tr.querySelector('.obtained').value) || 0;
totalSum += t; obtainedSum += o;
});
const agg = totalSum > 0 ? (obtainedSum/totalSum*100) : 0;
document.getElementById('aggregateVal').textContent = agg.toFixed(2) + '%';
updateProgress();
}
addRowBtn.addEventListener('click', ()=>addMarksRow());
addMarksRow(); // start with one row
/* ---------- Branch selection chips ---------- */
const branches = [
{code:'CSE', name:'Computer Science'},
{code:'CSM', name:'AI & ML'},
{code:'CSD', name:'Data Science'},
{code:'ECE', name:'Electronics & Comm.'},
{code:'EEE', name:'Electrical & Electronics'},
{code:'ME', name:'Mechanical'},
{code:'CE', name:'Civil'},
];
const branchGrid = document.getElementById('branchGrid');
const branchHidden = document.getElementById('branch');
const branchErr = document.getElementById('branchErr');
branches.forEach(b=>{
const div = document.createElement('div');
div.className = 'branch-chip';
div.innerHTML = `
${b.code}${b.name}`;
div.addEventListener('click', ()=>{
document.querySelectorAll('.branch-chip').forEach(c=>c.classList.remove('selected'));
div.classList.add('selected');
branchHidden.value = b.code;
branchErr.textContent = '';
updateProgress();
});
branchGrid.appendChild(div);
});
/* ---------- Field validation ---------- */
function validateField(field){
const input = field.querySelector('input,select,textarea');
const errEl = field.querySelector('.err-msg');
let msg = '';
if(!input) return true;
const val = input.value.trim();
if(field.hasAttribute('data-required') && !val){
msg = 'This field is required.';
} else if(input.id === 'email' && val && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val)){
msg = 'Enter a valid email address.';
} else if(input.id === 'mobile' && val && !/^[6-9]\d{9}$/.test(val)){
msg = 'Enter a valid 10-digit mobile number.';
}
if(msg){
field.classList.add('invalid');
field.classList.remove('valid');
errEl.textContent = msg;
return false;
} else {
field.classList.remove('invalid');
if(val) field.classList.add('valid'); else field.classList.remove('valid');
errEl.textContent = '';
return true;
}
}
document.querySelectorAll('.field[data-required], .field:has(#email), .field:has(#mobile)').forEach(field=>{
const input = field.querySelector('input,select,textarea');
if(input){
input.addEventListener('blur', ()=>validateField(field));
input.addEventListener('input', ()=>{ if(field.classList.contains('invalid')) validateField(field); updateProgress(); });
}
});
/* ---------- Progress indicator ---------- */
function updateProgress(){
const requiredFields = Array.from(document.querySelectorAll('[data-required]'))
.map(f => f.tagName === 'SELECT' ? f : f.querySelector('input,select,textarea'))
.filter(Boolean);
let filled = 0;
requiredFields.forEach(input=>{
if(input && input.value && input.value.trim()) filled++;
});
if(branchHidden.value) filled++;
const totalCount = requiredFields.length + 1; // +1 for branch
const pct = totalCount > 0 ? Math.round((filled/totalCount)*100) : 0;
document.getElementById('progressText').textContent = pct + '%';
}
updateProgress();
/* ---------- Save draft (localStorage-free: just toast, since sandbox restricts storage) ---------- */
document.getElementById('saveDraftBtn').addEventListener('click', ()=>{
showToast('Draft captured — remember to Submit before closing.');
});
/* ---------- Print ---------- */
document.getElementById('printBtn').addEventListener('click', ()=>window.print());
/* ---------- Submit ---------- */
form.addEventListener('submit', function(e){
e.preventDefault();
let valid = true;
document.querySelectorAll('.field[data-required], .field:has(#email), .field:has(#mobile)').forEach(field=>{
if(!validateField(field)) valid = false;
});
if(!branchHidden.value){
branchErr.textContent = 'Please select a branch preference.';
valid = false;
} else {
branchErr.textContent = '';
}
if(!document.getElementById('declaration').checked){
showToast('Please accept the declaration before submitting.');
valid = false;
}
if(!valid){
showToast('Please fix the highlighted fields.');
const firstInvalid = document.querySelector('.field.invalid, #branchErr');
if(firstInvalid) firstInvalid.scrollIntoView({behavior:'smooth', block:'center'});
return;
}
showToast('Application submitted successfully!');
document.getElementById('submitBtn').disabled = true;
document.getElementById('submitBtn').textContent = 'Submitted ✓';
});
form.addEventListener('reset', ()=>{
setTimeout(()=>{
marksBody.innerHTML = '';
rowCount = 0;
addMarksRow();
recalcAggregate();
document.querySelectorAll('.branch-chip').forEach(c=>c.classList.remove('selected'));
branchHidden.value = '';
photoBox.innerHTML = '
Click to
upload photo';
rankConditional.style.display = 'none';
document.querySelectorAll('.field').forEach(f=>{f.classList.remove('invalid','valid');});
document.getElementById('submitBtn').disabled = false;
document.getElementById('submitBtn').textContent = 'Submit Application';
updateProgress();
}, 0);
});
})();
Welcome to B-Category Seats
Server Error