Question

Locked

website building query ( Javascript, HTML)

By subhadeep2007 ·
<html>
<body>
<head>

<script type='text/javascript'>


function ipxac() {
if(stkgenValidator()) {
if(isvalid()) {
if(isvalid1()) {
return true;
}
}
}
return false;

}

function stkgenValidator(){
// Make quick references to our fields
var name = document.getElementById('name');
var vendor = document.getElementById('vendor');
var library = document.getElementById('library');
var version = document.getElementById('version');
// Check each input in the order that it appears in the form!
if(isC_like(name, "Please enter a proper module name(naming convention like C variable)")){
if(notEmpty(vendor, "Please enter a vendor name")){
if(notEmpty(library, "Please enter a library name")){
if(isDotted_like(version, "Please enter a proper module version(must be of dotted number format")){
return true;
}
}
}
}
return false;
}

function isvalid()
{ var maxmul=200;
var minmul=0;
var alertmsg="Fill the following n";
len=alertmsg.length;
var x=document.getElementById("form1");
for (var i=0;i<x.length;i++)
{
var s=Math.floor(i/8)+1;
var table=document.getElementById("table");
var rowCount=table.rows.length;
for ( var t=1; t<rowCount; t++) {
if(s==t)
{
var j= table.rows[t].cells[0].innerHTML;
}
}

if ((x.elements.value==null) || (x.elements.value==""))
{if((x.elements.name=="if_name"))
{
var k=i+1;
{
if((x.elements[k].value=="0"))
{
if((x.elements[k+1].value=="0")) {
i=i+4;
continue;
}
}

}
}
if(!(x.elements.name=="datafile")){
if(x.elements.name=="if_name")
{
alertmsg+="Interface name with Id.no:"+j+"\n";
}
if(x.elements.name=="if_dir")
{
alertmsg+=" Direction of Interface with Id.no:"+j+"\n";
}

if(x.elements.name=="if_type")
{
alertmsg+=" Interface type Interface with Id.no:"+j+"\n";
}

}


}
if((x.elements.name=="if_multiplicity"))
{
var mulValue=x.elements.value;
if(isNaN(mulValue)){
alertmsg+="non numeric value of multiplicity with Id.no:"+j+"\n";
}
if(!isNaN(mulValue)){
if((x.elements.value < minmul) || (x.elements.value >maxmul))
{
alertmsg+="Enter multiplicity between 0 and "+maxmul+" at Id.no"+j+"\n";
}
}
}

if(x.elements.value=="0")
{
if(x.elements.name=="if_dir")
{
alertmsg+=" Direction of Interface with Id.no:"+j+"\n";
}

if(x.elements.name=="if_type")
{
alertmsg+=" Interface type Interface with Id.no:"+j+"\n";
}

}
if(x.elements.name=="datafile")
{
if ((x.elements.value==null) || (x.elements.value==""))
{
alertmsg+="datafile not specified";
}
}
}
if(alertmsg.length==len)
{
return true;
}
else
{
alert(alertmsg);
return false;
}
}




function isvalid1()
{ var maxmul=200;
var minmul=0;
var alertmsg="Fill the following n";
len=alertmsg.length;
var x=document.getElementById("form1");
for (var i=0;i<x.length;i++)
{
var s=Math.floor(i/6)+1;
var table=document.getElementById("table1");
var rowCount=table.rows.length;
var j;
for ( var t=1; t<rowCount; t++) {
if(s==t)
{
j= table.rows[t].cells[0].innerHTML ;
}
}

if ((x.elements.value==null) || (x.elements.value==""))
{if((x.elements.name=="if_name1"))
{
var k=i+1;

if((x.elements[k].value=="0"))
{
if((x.elements[k+1].value=="")) {
i=i+2;
continue;
}
}


}

if(x.elements.name=="if_name1")
{

alertmsg+="Parameter name with Id.no:"+j+"\n";
}
if(x.elements.name=="if_default")
{

alertmsg+="Default value of Parameter with Id.no:"+j+"\n";
}
}
if(x.elements.value=="0")
{
if(x.elements.name=="if_type1")
{

alertmsg+="Parameter type with Id.no:"+j+"\n";
}

}

}
if(alertmsg.length==len)
{
return true;
}
else
{
alert(alertmsg);
return false;
}
}








function notEmpty(elem, helperMsg){
var varExp = /^[\s]+$/;
if(elem.value.length == 0 || elem.value.match(varExp)){
alert(helperMsg);
elem.focus(); // set the focus to this input
return false;
}
return true;
}


function isC_like(elem, helperMsg) {
var varExp = /^[\s]*[a-zA-Z_][a-zA-Z0-9_]*[\s]*$/;
if(elem.value.match(varExp)) {
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}

function isDotted_like(elem,helperMsg) {
var varExp = /^[\s]*[0-9\.]*[0-9][\s]*$/;
if(elem.value.match(varExp)) {
return true;
}else{
alert(helperMsg);
elem.focus();
return false;
}
}



function goBack()
{
window.history.go(-2);
}





function deleteRow(r)
{

var i=r.parentNode.parentNode.rowIndex;
document.getElementById("table").deleteRow(i);

}
function deleteRow1(r)
{

var i=r.parentNode.parentNode.rowIndex;
document.getElementById("table1").deleteRow(i);

}

function addrow()
{ var maxchar=40;
var table=document.getElementById("table");
var rowCount=table.rows.length;
var row=table.insertRow(rowCount);
var colCount=table.rows[0].cells.length;
for(var i=0;i<colCount+1;i++)
{
var newno=table.rows[rowCount-1].cells[0].innerHTML;

var newcell=row.insertCell(i);
if(i==0){
newcell.innerHTML=++newno;
}
else
{
newcell.innerHTML=table.rows[1].cells.innerHTML;
}
switch(newcell.childNodes[0].type)
{
case "text":if(newcell.childNodes[0].name=="if_comment") {
newcell.childNodes[0].value="(not more than "+maxchar+" characters)";
break;
}
if(newcell.childNodes[0].name=="if_multiplicity") {
newcell.childNodes[0].value="1";
break;
}

newcell.childNodes[0].value="";
break;
case "button":newcell.childNodes[0].value="Delete";
break;
case "select-one":newcell.childNodes[0].selectedIndex=0;
break;
}
}
}


function addrow1()
{
var table=document.getElementById("table1");
var rowCount=table.rows.length;
var row=table.insertRow(rowCount);
var colCount=table.rows[5].cells.length;
for(var i=0;i<colCount+1;i++)
{
var newno=table.rows[rowCount-1].cells[0].innerHTML;

var newcell=row.insertCell(i);
if(i==0){
newcell.innerHTML=++newno;
}
else
{
newcell.innerHTML=table.rows[6].cells.innerHTML;
}
/*
switch(newcell.childNodes[0].type)
{
case "text":newcell.childNodes[0].value="";
break;
case "button":newcell.childNodes[0].value="Delete";
break;
case "select-one":newcell.childNodes[0].selectedIndex=0;
break;
case "checkbox":newcell.childNodes[0].selectedIndex=0;
break;
}
*/

}
}
function addrow2()
{
var table=document.getElementById("table2");
var rowCount=table.rows.length;
var row=table.insertRow(rowCount);
var colCount=table.rows[0].cells.length;
for(var i=0;i<colCount+1;i++)
{
var newno=table.rows[rowCount-1].cells[0].innerHTML;

var newcell=row.insertCell(i);
if(i==0){
newcell.innerHTML=++newno;
}
else
{
newcell.innerHTML=table.rows[1].cells.innerHTML;
}
}
}



</script>
</head>

<form method="post" action="/cgi-bin/upload.pl" enctype="multipart/form-data" >
<fieldset>
<legend> Upload and make changes in an existing interface description file:</legend>
<input type="file" name="upload_file"/>
<input type="submit" value="upload"/>
</fieldset>
</form>


<form id='form1' onsubmit='return ipxac()' action="http://localhost/stkgen/cgi-bin/ipexac5.cgi" method="POST" >
<head>
<style type="text/css">
p {color:green;font-weight:900;}
</style>
</head>
<hr/>
<fieldset>
<legend> VLNV:</legend>
<table id="tblVlnv" name="tblVlnv" border='0' cellpadding='0' cellspacing='0'>
<tr>
<td>Module Name:</td>
<td><input type="text" id='name' name='name'></td>
<td>Vendor Name:</td>
<td> <input type="text" id='vendor' name='vendor' value='TI'></td>
</tr>
<tr>
<td>Module Version:</td>
<td> <input type="text" id='version' name='version' value='1.0'></td>
<td>Library:</td>
<td> <input type="text" id='library' name='library' value='SMS'></td>
</tr>
<tr>
<td>Description:</td><td> <textarea rows='2' cols='25' id='description' name='description'></textarea></td></tr><tr><td></td>
</tr>
</table>
</fieldset>
<hr/>



<fieldset>
<legend> Interfaces</legend>
<table id="table" >
<tr>
<th>ID</th>
<th><acronym title="Name of the interface">Interface Name</acronym></th>
<th><acronym title="Type of the interface">Interface Type</acronym></th>
<th><acronym title="Direction of the pin">Direction</acronym></th>
<th><acronym title="Payload">Payload DT</acronym></th>
<th><acronym title="No of pins">N-Pins</acronym></th>
<th><acronym title="Alias of the interface">Interface-Alias</acronym></th>
<th><acronym title="Description of the interface">Description</th>

</tr>
<tr>
<td>1</td>
<td><input type="text" name="if_name"/> </td>
<td><select name="if_type">
<option value="0" selected="selected">(please select:)</option>
<option value="intr_pulse">Interrupt:Pulse</option>
<option value="intr_level">Interrupt:Level</option>
<option value="reset_pulse">Reset:Pulse</option>
<option value="reset_level">Reset:Level</option>
<option value="clock">Clock</option>
<option value="rpin">Rpin</option>
<option value="dpin">Dpin</option>
<option value="mpin">TLM2:LT</option>
</select>
</td>
<td><select name="if_dir">
<option value="0" selected="selected">(please select:)</option>
<option value="in">in</option>
<option value="out">out</option>

</select>
</td>
<td><input type="text" name="if_payload" onload "set_payload(this)"/> </td>
<td><input type="text" name="if_multiplicity" value="1"/></td>
<td><input type="text" name="if_alias"/> </td>
<td><input type="text" name="if_comment" value="(not more than 40 characters)"/></td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"/> </td>
</tr>
<tr>
<td> 2 </td>
<td><input type="text" name="if_name"/> </td>
<td><select name="if_type">
<option value="0" selected="selected">(please select:)</option>
<option value="intr_pulse">Interrupt:Pulse</option>
<option value="intr_level">Interrupt:Level</option>
<option value="reset_pulse">Reset:Pulse</option>
<option value="reset_level">Reset:Level</option>
<option value="clock">Clock</option>
<option value="rpin">Rpin</option>
<option value="dpin">Dpin</option>
<option value="mpin">TLM2:LT</option>
</select>
</td>
<td><select name="if_dir">
<option value="0" selected="selected">(please select:)</option>
<option value="in">in</option>
<option value="out">out</option>

</select>
</td>
<td><input type="text" name="if_payload" onload "set_payload(this)"/> </td>
<td><input type="text" name="if_multiplicity" value="1"/></td>
<td><input type="text" name="if_alias"/> </td>
<td><input type="text" name="if_comment" value="(not more than 40 characters)"/></td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"/> </td>
</tr>
<tr>
<td>3</td>
<td><input type="text" name="if_name"/> </td>
<td><select name="if_type">
<option value="0" selected="selected">(please select:)</option>
<option value="intr_pulse">Interrupt:Pulse</option>
<option value="intr_level">Interrupt:Level</option>
<option value="reset_pulse">Reset:Pulse</option>
<option value="reset_level">Reset:Level</option>
<option value="clock">Clock</option>
<option value="rpin">Rpin</option>
<option value="dpin">Dpin</option>
<option value="mpin">TLM2:LT</option>
</select>
</td>
<td><select name="if_dir">
<option value="0" selected="selected">(please select:)</option>
<option value="in">in</option>
<option value="out">out</option>

</select>
</td>
<td><input type="text" name="if_payload" onload "set_payload(this)"/> </td>
<td><input type="text" name="if_multiplicity" value="1"/></td>
<td><input type="text" name="if_alias"/> </td>
<td><input type="text" name="if_comment" value="(not more than 40 characters)"/></td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"/> </td>

</tr>
<tr>
<td>4</td>
<td><input type="text" name="if_name"/> </td>
<td><select name="if_type">
<option value="0" selected="selected">(please select:)</option>
<option value="intr_pulse">Interrupt:Pulse</option>
<option value="intr_level">Interrupt:Level</option>
<option value="reset_pulse">Reset:Pulse</option>
<option value="reset_level">Reset:Level</option>
<option value="clock">Clock</option>
<option value="rpin">Rpin</option>
<option value="dpin">Dpin</option>
<option value="mpin">TLM2:LT</option>
</select>
</td>
<td><select name="if_dir">
<option value="0" selected="selected">(please select:)</option>
<option value="in">in</option>
<option value="out">out</option>

</select>
</td>
<td><input type="text" name="if_payload" onload "set_payload(this)"/> </td>
<td><input type="text" name="if_multiplicity" value="1"/></td>
<td><input type="text" name="if_alias"/> </td>
<td><input type="text" name="if_comment" value="(not more than 40 characters)"/></td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"/> </td>
</tr>
<tr>
<td>5</td>
<td><input type="text" name="if_name"/> </td>
<td><select name="if_type">
<option value="0" selected="selected">(please select:)</option>
<option value="intr_pulse">Interrupt:Pulse</option>
<option value="intr_level">Interrupt:Level</option>
<option value="reset_pulse">Reset:Pulse</option>
<option value="reset_level">Reset:Level</option>
<option value="clock">Clock</option>
<option value="rpin">Rpin</option>
<option value="dpin">Dpin</option>
<option value="mpin">TLM2:LT</option>
</select>
</td>
<td><select name="if_dir">
<option value="0" selected="selected">(please select:)</option>
<option value="in">in</option>
<option value="out">out</option>

</select>
</td>
<td><input type="text" name="if_payload" onload "set_payload(this)"/> </td>
<td><input type="text" name="if_multiplicity" value="1"/></td>
<td><input type="text" name="if_alias"/> </td>
<td><input type="text" name="if_comment" value="(not more than 40 characters)"/></td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"/> </td>
</tr>

<tr>
<td>6</td>
<td><input type="text" name="if_name"/> </td>
<td><select name="if_type">
<option value="0" selected="selected">(please select:)</option>
<option value="intr_pulse">Interrupt:Pulse</option>
<option value="intr_level">Interrupt:Level</option>
<option value="reset_pulse">Reset:Pulse</option>
<option value="reset_level">Reset:Level</option>
<option value="clock">Clock</option>
<option value="rpin">Rpin</option>
<option value="dpin">Dpin</option>
<option value="mpin">TLM2:LT</option>
</select>
</td>
<td><select name="if_dir">
<option value="0" selected="selected">(please select:)</option>
<option value="in">in</option>
<option value="out">out</option>

</select>
</td>
<td><input type="text" name="if_payload" onload "set_payload(this)"/> </td>
<td><input type="text" name="if_multiplicity" value="1"/></td>
<td><input type="text" name="if_alias"/> </td>
<td><input type="text" name="if_comment" value="(not more than 40 characters)"/></td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"/> </td>
</tr>



</table>
<br/>
<input type="button" value="Add Interface Row" onclick="addrow()"/>
</fieldset>
<hr/>


<fieldset>
<legend> Parameters:</legend>
<table id="table1" >
<tr>
<th>ID</th>
<th><acronym title="Name of the parameter">Parameter Name</acronym></th>
<th><acronym title="Type of the parameter">Parameter Type</acronym></th>
<th><acronym title="Default value">Default value</acronym></th>
<th><acronym title="User modification option">Can user update?</acronym></th>
<th><acronym title="Description of the parameter">Description</acronym></th>

</tr>
<tr>
<td>1</td>
<td><input type="text" name="if_name1" value="GEN_SSI_VER" readonly /> </td>
<td><select name="if_type1">
<option value="0" selected="selected">(please select:)</option>
<option value="int">int</option>
<option value="string">string</option>
<option value="boolean">boolean</option>
</select>
</td>
<td><input type="text" name="if_default" value="SSI" readonly /> </td>
<td><input type="checkbox" name="if_update" value="yes" /> Y<br /> </td>
<td><input type="text" name="if_desc1" /> </td>
</tr>
<tr>
<td>2</td>
<td><input type="text" name="if_name1" value="SPEC_VER" readonly /> </td>
<td><select name="if_type1">
<option value="0" selected="selected">(please select:)</option>
<option value="int">int</option>
<option value="string">string</option>
<option value="boolean">boolean</option>
</select>
</td>
<td><input type="text" name="if_default" value="1" readonly /> </td>
<td><input type="checkbox" name="if_update" value="yes" /> Y<br /> </td>
<td><input type="text" name="if_desc1" /> </td>
</tr>
<tr>
<td>3</td>
<td><input type="text" name="if_name1" value="GEN_STK_VER" readonly /> </td>
<td><select name="if_type1">
<option value="0" selected="selected">(please select:)</option>
<option value="int">int</option>
<option value="string">string</option>
<option value="boolean">boolean</option>
</select>
</td>
<td><input type="text" name="if_default" value="STK1.5" readonly /> </td>
<td><input type="checkbox" name="if_update" value="yes" /> Y<br /> </td>
<td><input type="text" name="if_desc1" /> </td>
</tr>
<tr>
<td>4</td>
<td><input type="text" name="if_name1" value="GEN_CLASS_T" readonly /> </td>
<td><select name="if_type1">
<option value="0" selected="selected">(please select:)</option>
<option value="int">int</option>
<option value="string">string</option>
<option value="boolean">boolean</option>
</select>
</td>
<td><input type="text" name="if_default" value="dmtimer_t" readonly /> </td>
<td><input type="checkbox" name="if_update" value="yes" /> Y<br /> </td>
<td><input type="text" name="if_desc1" /> </td>
</tr>
<tr>
<td>5</td>
<td><input type="text" name="if_name1" value="GEN_SCONS_MODULE" readonly /> </td>
<td><select name="if_type1">
<option value="0" selected="selected">(please select:)</option>
<option value="int">int</option>
<option value="string">string</option>
<option value="boolean">boolean</option>
</select>
</td>
<td><input type="text" name="if_default" value="DMTIMER_SC" readonly /> </td>
<td><input type="checkbox" name="if_update" value="yes" /> Y<br /> </td>
<td><input type="text" name="if_desc1" /> </td>
</tr>

<tr>
<td>6</td>
<td><input type="text" name="if_name1" /> </td>
<td><select name="if_type1">
<option value="0" selected="selected">(please select:)</option>
<option value="int">int</option>
<option value="string">string</option>
<option value="boolean">boolean</option>
</select>
</td>
<td><input type="text" name="if_default" /> </td>
<td><input type="checkbox" name="if_update" value="yes" /> Y<br /> </td>
<td><input type="text" name="if_desc1" /> </td>
<td><input type="button" value="Delete" onclick="deleteRow1(this)"/> </td>

</tr>

</table>
<br/>
<input type="button" value="Add Parameter Row" onclick="addrow1()"/>
</fieldset>
<hr/>


<fieldset>
<legend> Files:</legend>
<table id="table2" >
<tr>
<th>ID</th>
<th><acronym title="Name of the file">File Name</acronym></th>
<th><acronym title="Header file or not">Is include file?</acronym></th>
<th><acronym title="Description of the file">Description</acronym></th>

</tr>
<tr>
<td>1</td>
<td><input type="text" name="if_name2" /> </td>
<td><input type="checkbox" name="if_include" value="yes" checked />[Y]<br /> </td>
<td><input type="text" name="if_desc2" /> </td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"/> </td>
</tr>
<tr>
<td>2</td>
<td><input type="text" name="if_name2" /> </td>
<td><input type="checkbox" name="if_include" value="yes" checked />[Y]<br /> </td>
<td><input type="text" name="if_desc2" /> </td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"/> </td>
</tr>
<tr>
<td>3</td>
<td><input type="text" name="if_name2" /> </td>
<td><input type="checkbox" name="if_include" value="yes" checked />[Y]<br /> </td>
<td><input type="text" name="if_desc2" /> </td>
<td><input type="button" value="Delete" onclick="deleteRow(this)"/> </td>
</tr>
</table>
<br/>
<input type="button" value="Add File Row" onclick="addrow2()"/>
</fieldset>
<hr/>



<input type='submit' value='Submit' />
<input type='reset' value='Reset' />
</form>

<input type="button" value="Back" onclick="goBack()" />

</body>
</html>


Now the problem with this website I am building is-
->In parameter section parameter type is a mandatory field if you put values in parameter name and dafault value fields. The javascript for that I have written in function isvalid1(). Now the id no in the javacript alert needs to be exact as it is on the html screen. But the alert that is coming has the total number of rows as id instead of actual id no.

Please check the problem asap and a well thought solution will be highly accepted.

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Share your knowledge
Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums