我如何在特定文本框中获得差异值

时间:2015-08-22 07:29:13

标签: php ajax

我在所有文本框字段中获取所有ajax值。如何在特定字段中获取特定值... plz帮助我如何在位置字段中获取位置,在machin_no字段中的machin_no等等。发送下面的代码为这个问题......

function getuserName(strURL)
{   

    var req = getXMLHTTP();     
    if (req) 
    {
        //function to be called when state is changed
        req.onreadystatechange = function()
        {
            //when state is completed i.e 4
            if (req.readyState == 4) 
            {           
                // only if http status is "OK"
                if (req.status == 200)
                {   

                        document.getElementById('location').value=req.responseText;
                        document.getElementById('msrno').value=req.responseText;                        
                        document.getElementById('cust_no').value=req.responseText;                      
                    //var name = document.getElementById('location').value=req.responseText;                        


                } 
                else 
                {
                    alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                }
            }               
         }          
         req.open("GET", strURL, true);
         req.send(null);
    }           
}
</script>



</head>
<body>
<div id="content" class="regtitle">

      <div id="regform">
        <form name="formreg">
            <div id="rowone">
                <label>Customer Name</label> <input name="custname" id="custname" type="text"  placeholder="Customer Name" onkeydown="getuserName('getdata.php?custname='+this.value)"/>
                <label>Current Locaiton</label> <input name="location" id="location" type="text" placeholder="Current Location" />
            </div>

            <div id="rowtwo">
            <span><label>Machine Sr. No.</label> <input name="msrno" id="msrno" type="text" placeholder="Machine Sr. No."/></span>

            <span id="custno"><label>Customer No.</label><input name="custno" id="cust_no" type="text" placeholder="Customer No." />
            </span>`enter code here`

1 个答案:

答案 0 :(得分:0)

将值放入字段内的jQuery如下所示。您还可以将变量设置为等于元素的字段值。

$('#location').val() = 'Your location string, or variable';