Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript validation for dynamically added textarea

Posted on 2003-11-30
3
Medium Priority
?
1,298 Views
Last Modified: 2012-06-27
I am using the insRow() function to add rows to a table.
function insRow()
{
    var x=document.getElementById('myTable').insertRow(TRCount)
    var y=x.insertCell(0)
    var z=x.insertCell(1)
    showCount = TRCount + 1
    y.innerHTML=showCount
    z.innerHTML="<TEXTAREA style=overflow:hidden NAME='task"+TRCount+"' ROWS='' COLS='45'></TEXTAREA>"
    TRCount++;
}
But when I submit the form i need to make sure that none of the textarea is empty(Simple javascript validation).But it does not seem to work here.

function submitForm()
{
   var count = document.getElementById("mytable").rows.length

   for(var i=0; i<count; i++)
      {
         alert("task"+i.value)
         if("task'"+i+"'".value=="")
       {
                 alert("Please Enter Task");
                 return;
           }
          }
     form1.action="addAdminReport.jsp";
     form1.submit();
      
}
Please Help
0
Comment
Question by:sangeeta9189
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
NetGroove earned 0 total points
ID: 9848730
Here my proposal:

<html>
<head>
<script>
var TRCount=0;
function insRow(){
    var x=document.getElementById('myTable').insertRow(TRCount)
    var y=x.insertCell(0)
    var z=x.insertCell(1)
    showCount = TRCount + 1
    y.innerHTML=showCount
    z.innerHTML="<TEXTAREA style='overflow:hidden' NAME='task"+TRCount+"' ROWS='' COLS='45'></TEXTAREA>"
    TRCount++;
}

function submitForm(theForm){
   elem = theForm.elements;
   for(var i=0; i<elem.length; i++){
     if(elem[i].type=='textarea' && elem[i].name.substr(0,4)=='task'){
       alert(elem[i].name+": "+elem[i].value) // only for debugging
       if(elem[i].value==""){
         alert("Please Enter Task");
         elem[i].focus();
         return false;
       }
     }
   }
   theForm.action="addAdminReport.jsp";
   return true;
}
</script>
</head>
<body>
<form name="form1" onSubmit="return submitForm(this)">
<table id="myTable">
</table>
<input type=button value="Add" onClick="insRow()">
<input type=submit>
</body>
</html>


0
 

Expert Comment

by:anshul9189
ID: 9848786
gr8
;)
works perfectly fine
0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9848880
Thanks for the points.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question