1

I have the ajax, which runs when the user writes something ind input id=2

HTML:

<input id="2" type="text" onkeyup="posttitulo(this.value)" />

SCRIPT:

function posttitulo(value){
$.post("getdata/posttitulo.php",{partialStates:value});
}

The code works perfectly.. The problem is that I have the javascript function which onclick copies value of another input id=1, in this case id=2 has the value without typing and function posttitulo(value) doesn't work..

So I need Ajax to be executed if:

1) User writes something onkeyup="posttitulo(this.value);

2) the value of id=1 is copied to id=2..

Hope that I explained the problem.. Thanks in advance

asked Mar 30, 2015 at 7:40
2
  • How about <input id="2" type="text" onchange="posttitulo(this.value)" />, did you try it? Commented Mar 30, 2015 at 7:46
  • Yes, Already tryed, doesn't work Commented Mar 30, 2015 at 7:56

4 Answers 4

2

Do $('#2').keyup(); after you copied a value in the function, which fires onclick.

answered Mar 30, 2015 at 7:44
Sign up to request clarification or add additional context in comments.

Comments

0

create an event listener change() on id=2:

$(document).ready(function(){
 $("#2").change(function(){
 var value=$("#2").val();
 $.post("getdata/posttitulo.php",{partialStates:value});
 });
});
answered Mar 30, 2015 at 7:44

Comments

0

You could go with firing the event on the input or recycle the function you already declared. When the button is clicked read the value of the id2 Element and call the posttitulo function with the value as argument.

function posttitulo(value){
 console.log('AJAX POST:', value);
}
function buttonClicked() {
 var value = document.getElementById('id2').value;
 posttitulo(value);
}

Fiddle

answered Mar 30, 2015 at 7:47

Comments

0

May be this will work in your case.

<input id="1" type="text" onclick="yourreplacefunction(this.value,2)" />
$(document).on("change keyup", "input", function() {
 $.post("getdata/posttitulo.php",{partialStates:value},function(response){
 //Do with your response
 });
});
function yourreplacefunction(value,toid) {
 $('#'+toid).val(value);
}
answered Mar 30, 2015 at 7:49

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.