javascript - Insert the attribute value of input element in form -


i have form no id or class. need insert attribute values input elements.

<form>     <tr><td><input type="text" name="x"/></td></tr>     <tr><td><input type="text" name="y"/></td></tr>     <tr><td><input type="text" name="z"/></td></tr> </form> 

here's jquery tried:

var x = $('form').find('input').first().val("some_value"); var y = $('form').find('input').second().val("some_value"); var z = $('form').find('input').third().val("some_value"); 

// there possible way?

var x  = $("form").find('input[name="x"]').val("some_value"); 

you can use attribute equals selector [name=”value”] uniquely identify inputs

$('input[name=x]').val("some_value1"); $('input[name=y]').val("some_value2"); $('input[name=z]').val("some_value3"); 

although wont recommend method used assign values input, suggest use find() once , use returned object collection assign values. reduce processing time , increase performance.

var = $('form').find('input'); all.eq(0).val("some_value1"); all.eq(1).val("some_value2"); all.eq(2).val("some_value3"); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -