2

My HTML table populates its rows dynamically. One of the table data is a dropdown with thesame options. What I want to do is when I change the value of the first, the remaining dropdowns on the other rows will have a selected value, thesame as what is recently selected.

If I change the selected value on the second row, the rest of the dropdowns will be like the second, without affecting the value of the first. Here are a few codes:

<table id="CheckDetails" width="60%">
<tr>
<th>Date</th>
<th>Category</th>
<th>Description</th>
<th>Amount</th>
 </tr>
 <tr class="row1">
<td><input name="date1" id="date1" class="" value="22-09-2013" /></td>
<td><select name="category" id="cat0" class="dropdown" >
    <option value="0">[-- Please Choose --]</option>
    <option value="1">References</option>
    <option value="2">Inspirational</option>
    </select>
</td>
<td><input type="text" class="entry" name="desc" id="desc0" value="1"/></td>
<td><input type="text" class="entry" name="amt" value="420.83333333333"/></td>
 </tr>
 <tr class="row1">
<td><input name="date1" id="date1" class="" value="22-09-2013" /></td>
<td><select name="category" id="cat0" class="dropdown" >
    <option value="0">[-- Please Choose --]</option>
    <option value="1">References</option>
    <option value="2">Inspirational</option>
    </select>
</td>
<td><input type="text" class="entry" name="desc" id="desc0" value="1"/></td>
<td><input type="text" class="entry" name="amt" value="420.83333333333"/></td>
 </tr>
 <tr class="row1">
<td><input name="date1" id="date1" class="" value="22-09-2013" /></td>
<td><select name="category" id="cat0" class="dropdown" >
    <option value="0">[-- Please Choose --]</option>
    <option value="1">References</option>
    <option value="2">Inspirational</option>
    </select>
</td>
<td><input type="text" class="entry" name="desc" id="desc0" value="1"/></td>
<td><input type="text" class="entry" name="amt" value="420.83333333333"/></td>
 </tr>

I am working with php for this project. Any help is appreciated. Thanks!

1 Answer 1

1

Try

$('select[name="category"]').change(function(){
    var $this = $(this), $nextAll = $this.closest('tr').nextAll('tr').find('select[name="category"]');

    $nextAll.val($this.val())
});

Demo: Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

It works! Thank you so much, my problem now is that the description is supposed to change depending on the selected value. But it doesnt...

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.