EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Steve2106 on December 18, 2019, 09:27:59 AM



Title: Getting field value from form
Post by: Steve2106 on December 18, 2019, 09:27:59 AM
Hi There,

I have a form and would like to get the value of a field in that form. So if I have this form:
    <form enctype="multipart/form-data" id="ff" name="ff" method="post">
        <table border="0" style="margin-top:20px;width: 100%;" >
            <tr>
                <label>Site:</label>
                <input name="site" id="site" style="width: 190px;" class="easyui-textbox" >
            </tr>
            <tr>
                <label>Job:</label>
                <input name="job" id="job" style="width: 190px;" class="easyui-textbox" >
            </tr>
            <tr>
                <td><input id="fb" name="userfile[]" type="text" style="width: 100%;" ></td>
                <td style="width: 90px; text-align: right;"><a id="btn-upload" href="javascript:void(0)">Upload</a> </td>           
            </tr>
        </table>
    </form>
 how do I get the vale of the field with id="site"

Thanks for your help.

Best Regards,

Steve.


Title: Re: Getting field value from form
Post by: stworthy on December 19, 2019, 12:23:01 AM
Call the native method serializeArray to get all the form values.
Code:
var values = $('#ff').serializeArray();
// find  the value you expect
var item = values.filter(item => item.name === 'name');
console.log(item)


Title: Re: Getting field value from form
Post by: Steve2106 on December 20, 2019, 02:31:40 PM
Hi stworthy,

Thanks for the reply.
I tried the code adapted a little like this:
            values = $('#ff').serializeArray();
            // find  the value you expect
            var item = values.filter(item => item.name === 'site');
            $.messager.alert('Message','Site is:<br /><br />' . item,'error');
But I get the attached returned:

Any idea why.

Best Regards,

Steve.


Title: Re: Getting field value from form
Post by: Aod47 on December 20, 2019, 07:22:58 PM
$.messager.alert('Message','Site is:<br /><br />' . item,'error');

to

$.messager.alert('Message','Site is:<br /><br />' + item.name,'error');