John Davidson

php - jquery event method to get input

0 comments
Message:


I've used jquery to get an "id" as a value for an input according to a dropdown value. Now the problem is, I want to use the 'id' to insert value to some other inputs. I don't know which event method to be used. For testing, I used the keyup method to check if the code works, when I manually type in a number, it works. So the problem is with the event method I choose. Please give me some suggestions.


    //Get id
$(document).ready(function() {
$('#salary_eid').change(function() {
var sid = $(this).val();
var data_String = 'sid=' + sid;
$.get('search1.php', data_String, function(result) {

$.each(result, function(){
$('#can').val(this.c_id);


});
});
});

//display other information
$('#can').change(function() {
var id = $(this).val();
var data_String1 = 'id=' + id;
$.get('search.php', data_String1, function(result1) {

$.each(result1, function(){
$('#morning_rate').val(this.cMorning);
$('#night_rate').val(this.cNight);
$('#ot_rate').val(this.clientOt);

});
});
});
});

<label>Name</label>
<input type="text" name="salary_eid" />
<select id="salary_eid">
<option>opt1</option>
<option>opt2</option>
</select>

<input type="hidden" name="can" id="can" class="form-control" >


My Answer:
input value using the `val()` method. Here's an example code snippet:

html



Get Input Value













In this code, we have an input field with the id `myInput` and a button with the id `getValueBtn`. When the button is clicked, we use the `val()` method to get the value of the input field and display it in an alert box.

Rate this post

4 of 5 based on 4399 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us