jquery parent().find(input).val(); accessing two input fields in one table cell on click

I am trying to get values on two input fields (a text field and a select field) inside a table cell with on click button.

<td>
    <input type="text" onkeypress="return validateNumber(event);" value="'+rate_value+'" class="thinpt" maxlength="3" />
    <select class="thinpt1" value="'+format+'">
        <option value="21">Seconds</option>
        <option value="22">Minutes</option>
        <option value="33">Hours</option>
    </select>
    <button class="setstream" type="button" data-devicevalue="'+device_value+'" data-device="'+device_id+'" data-devicetype="'+device_type+'" data-gateway="'+gateway_id+'">SET</button>
    <span class="done grn"></span>
</td>

In jquery am using the below script to get the input from single text field.

var threshold  = $(this).parent().find('input').val();

I don't know how to get values of two different input box using the above jquery line.

Any help is appreciated.

Answers 1

  • Use the same val() function, create another variable to store your new value:

    var thinpt = $('.thinpt').val();
    var thinpt1 = $('.thinpt1').val();//get the value of the selected option
    var thinpt1text = $('.thinpt1 option:selected').text();//get the text of the selected option
    console.log(thinpt,thinpt1,thinpt1text);
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <input type="text" onkeypress="return validateNumber(event);" value="x" class="thinpt" maxlength="3" />
    <select class="thinpt1" name="format">
    <option value="21">Seconds</option>
    <option value="22">Minutes</option>
    <option value="33">Hours</option>
    </select>
    <button class="setstream" type="button" data-devicevalue="'+device_value+'" data-device="'+device_id+'" data-devicetype="'+device_type+'" data-gateway="'+gateway_id+'">SET</button><span class="done grn"></span>


Related Articles