EasyUI Forum
May 14, 2024, 10:16:13 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Getting field value from form  (Read 5714 times)
Steve2106
Newbie
*
Posts: 20


View Profile Email
« 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.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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)
Logged
Steve2106
Newbie
*
Posts: 20


View Profile Email
« Reply #2 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.
Logged
Aod47
Jr. Member
**
Posts: 83


View Profile
« Reply #3 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');
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!