2

I am working in a form where i insert some data and added this data to table. Now i want to validate a column And this column should not be the same. enter image description here

For example i want to prevent inserting same project name in table row. How it can be done in jQuery?

Here is my html code:

<div class="form-group">
								<div class="col-sm-2" style="padding-top: 5px">
									<label>Project : </label>
								</div>
								<div class="col-sm-10" style="padding-top: 5px">
									<input type="text" class="form-control" name="project"
										id="project">
								</div>
							</div>
              <div class="form-group">
							<div class="col-md-8 col-md-offset-4" style="padding-top: 5px">
								<input type="submit" class="btn btn-lg btn-success col-md-6"
									name="add" value="ADD" id="add">
							</div>
						</div>
   <div class="col-sm-10">
			<div class="panel panel-default">
				<div >
					<table class="table" id="showtable">
					<thead>
						<tr>
							<th>ACCOUNT HEAD</th>
							<th>DEBIT</th>
							<th>CREDIT</th>
							<th>CHEQUE</th>
							<th>PROJECT NAME</th>
							<th>MR.NO</th>
							<th>DEPT NAME</th>
						</tr>
						</thead>

					</table>
				</div>
			</div>
		</div>           

1 Answer 1

3

Use following code to check the column name is equal to input text.

add your column index to: .eq(column index)

Code Sample:

$('#showtable tbody tr').each(function () {
        $projectName = $(this).find('td:eq(4)').text();
        if ($projectName == $('#project').val()) {
            alert('ERROR')
        }
    });
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot brother. i think it will works for me . i have to write some code for verifying it will work or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.