Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Repost - question for fober1

New Here ,
Dec 08, 2008 Dec 08, 2008
Hello fober1,

You had responded to one of my posts and provided this sample code below, which I modified slightly and use, and it works great :

========================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>
<script language="JavaScript">
function checkrow(x){
error="";
if (! document.getElementById('material_'+x).value)
error=error + "Missing Material in "+x +"\n";

if (!document.getElementById('qty_'+x).value)
error=error + "Missing Quantity in "+x +"\n";

if (!document.getElementById('defined_'+x+'N').checked && !document.getElementById('defined_'+x+'Y').checked)
error=error + "Missing Defined in "+x +"\n";

if (error)
alert(error);

return(error);
}

function show(){
current= parseInt(document.getElementById('rows').value);
status= checkrow(current);
if ( status == '' && current <10){
try{
document.getElementById('row_'+ (current+1) ).style.display= 'table-row';
}
catch(err){
document.getElementById('row_'+ (current+1) ).style.display= 'block';
}
document.getElementById('rows').value= current+1;
}
}

function hide(){
current= parseInt(document.getElementById('rows').value);
if (current >1){
document.getElementById('row_'+ current ).style.display= 'none';
document.getElementById('rows').value= current-1;
}
}

function send(){
status="";
current= parseInt(document.getElementById('rows').value);
for (row=1; row<=current; row++)
checkrow(row);
if ( status != ''){
return(false);
}

}
</script>

<cfoutput>
<table border="1">
<form action="" method="post">
<tr>
<td colspan="4">
<input type="Submit" value="submit" onclick="return send();">
<input type="Hidden" name="rows" id="rows" value="1">
</td>
</tr>
<cfloop index="x" from="1" to="10">
<tr id="row_#x#" <cfif x GT 1>style="display:none"</cfif> >
<td>#x#</td>
<td>
<input type="Text" name="material_#x#" id="material_#x#">
</td>
<td>
<input type="Text" name="qty_#x#" id="qty_#x#">
</td>
<td>
<input type="Radio" name="defined_#x#" id="defined_#x#Y" value="Yes">Yes 
<input type="Radio" name="defined_#x#" id="defined_#x#N" value="No">No 
</td>
</tr>
</cfloop>
<tr>
<td colspan="4">
<input type="Button" value="Add" onclick="show()">
<input type="Button" value="Delete" onclick="hide()">
</td>
</tr>
</form>
</table>
</cfoutput>

<cfif isdefined("form.rows")>
<cfloop index="z" from="1" to="#form.rows#">
<cfoutput>
MATERIALS:#form['material_#z#']# / #form['qty_#z#']# / #form['defined_#z#']#<br>
<cfif form["defined_#z#"] is "Yes">
<!---<cfinclude template="">--->
</cfif>

</cfoutput>
</cfloop>
</cfif>

</body>
</html>


My question is how can I add a line item number to each row. The first row will always appear and have line item 1. If the add/next button is selected to add another row, then that line it would be 2, etec., all the way up to 10. I had some ideas and tried it but then the code stopped working, so I just put everything back.
317
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 08, 2008 Dec 08, 2008
LATEST
Hi Olivia,
When I run the script in this post, then I see a line item number on the left for each row.

Can you explain in more detail what you are looking for?

cheers,
fober

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources