javascript - How to find an element within another element without an id -


i trying change values of input element when value of select dropdown changes.

when select dropdown changes, want change hidden textbox , normal textbox td class="owner".

within td tag there multiple elements type="hidden" , 1 input type= text. want change values of element type="hidden" , id ending _lkid , _lkold , element within td of type="text" , within span tag

i don't have id of elements within td generated automatically nor can assign class elements. can assign class td.

i able change values of hidden text, unsure of how change type="text" field. pointers helpful.

jsfiddle : https://jsfiddle.net/4honph7n/3/

this js not best/effective code written, taking baby steps jquery

html

<select class="selectclass">     <option>option 1</option>     <option>option 2</option> </select> <table>     <tr>         <td class="owner">             <select>               <option>1</option>               <option>2</option>             </select>             <input type="hidden" id = "someid_lkid" value="00590000002bif7">             <input type="hidden" id = "someid_lkold" value="some text">                 <!-- there more hidden fields -->          <span class="lookupinput">             <input type="text" id = "someid" value="some text">          </span>         </td>     </tr> </table> 

js

$(document).ready(function () {     $('.selectclass').change(function() {         $('.owner').each(function(i) {             $(this).find("input[type='hidden']").each(function(){                if($(this).attr('id').indexof("lkid") > -1){                    $(this).val('new id');                    alert($(this).val());                }                if($(this).attr('id').indexof("lkold") > -1){                    $(this).val('new text');                    alert($(this).val());                }               })         })      }) }) 

if want assign same text/value inputs then

$(document).ready(function () {     $('.selectclass').change(function () {         $('.owner input[id$="lkid"]').val('new id');         $('.owner input[id$="lkold"]').val('new text');          $('.owner input:text').val('new val');      }) }) 

demo: fiddle


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -