DidierD
asked on
onclick does not work after onchange
This is probably easy, but i can not figure out how to do it. If i change the input field in the example and then click the button, only the onchange is executed. Why? How can i solve this? I want the onchange first executed and then the onclick.
<html>
<head>
<title>Untitled</title>
<script>
function gotoOK(){
alert("OK");
}
function doUpdate(){
alert("update");
}
</script>
</head>
<body>
<input type=button name=okButton value="OK" onclick="gotoOK()" >
<input type=text name=test value="" onchange="doUpdate()">
</body>
</html>
<html>
<head>
<title>Untitled</title>
<script>
function gotoOK(){
alert("OK");
}
function doUpdate(){
alert("update");
}
</script>
</head>
<body>
<input type=button name=okButton value="OK" onclick="gotoOK()" >
<input type=text name=test value="" onchange="doUpdate()">
</body>
</html>
this onchange
<input type=text name=test value="" onchange="doUpdate()">
takes the focus away from the button, halting the onclick event
try this instead
<html>
<head>
<title>Untitled</title>
<script>
function gotoOK(){
alert("OK");
}
function doUpdate(){
alert("update");
return true;
}
</script>
</head>
<body>
<input type=button name=okButton value="OK" onclick="doUpdate();gotoOK ()" >
<input type=text name=txtjkltest value="">
</body>
</html>
<input type=text name=test value="" onchange="doUpdate()">
takes the focus away from the button, halting the onclick event
try this instead
<html>
<head>
<title>Untitled</title>
<script>
function gotoOK(){
alert("OK");
}
function doUpdate(){
alert("update");
return true;
}
</script>
</head>
<body>
<input type=button name=okButton value="OK" onclick="doUpdate();gotoOK
<input type=text name=txtjkltest value="">
</body>
</html>
the onchange is called when you lose focus from the object,.
if you want both of the fucntion simply write them toghter:
<input type=text name=test value="" onchange="doUpdate();gotoO K()">
Nushi.
if you want both of the fucntion simply write them toghter:
<input type=text name=test value="" onchange="doUpdate();gotoO
Nushi.
everyone is typing answers at the same time.
DidierD
all of the above is correct.
you can accept all answers and split the points.
read my next comment where you will find more in formation in few minutes
(it takes time to type...)
:-))
Nushi.
DidierD
all of the above is correct.
you can accept all answers and split the points.
read my next comment where you will find more in formation in few minutes
(it takes time to type...)
:-))
Nushi.
whenever your text filed lose focus (by clicking the buton you set the focus to it)
it calls the onchange event so you never actually reach the gotoOK since you are never
able to click on the button:
text -> (go to button) -> lose focus -> call onchange -> open alert -> (get focus in order to close it)
from the above flow you can see that you never actually click on the button so
you didnt invoke the gotoOK function.
please feel free to ask if anything is still doesnt clear to u
after this explanation.
:-))
Nushi.
it calls the onchange event so you never actually reach the gotoOK since you are never
able to click on the button:
text -> (go to button) -> lose focus -> call onchange -> open alert -> (get focus in order to close it)
from the above flow you can see that you never actually click on the button so
you didnt invoke the gotoOK function.
please feel free to ask if anything is still doesnt clear to u
after this explanation.
:-))
Nushi.
>>everyone is typing answers at the same time.
>>(it takes time to type...)
and the way i type im lucky to get any answers in
>>(it takes time to type...)
and the way i type im lucky to get any answers in
Jester_48
::-))
its much faster with faces....
::-))
its much faster with faces....
Jes
im thinking of using a speach recognition software that will help me in this site...
Nushi.
im thinking of using a speach recognition software that will help me in this site...
Nushi.
DidierD
do you still have any questions?
if you do feel free to ask if you find my explanation doesnt statisfing
enought for your needs.
Nushi.
do you still have any questions?
if you do feel free to ask if you find my explanation doesnt statisfing
enought for your needs.
Nushi.
ASKER
Thanks for these fast replies. But i'm afraid they don't solve my problem.
On my real page i have more inputfields, with all a different onchange. I simplified my example a little too much. So onchange="doUpdate();gotoO K()" is not an option for me.
I tried the onblur, but only the alert with update appeared.
Didier
On my real page i have more inputfields, with all a different onchange. I simplified my example a little too much. So onchange="doUpdate();gotoO
I tried the onblur, but only the alert with update appeared.
Didier
so please explain what is it that you wish to do?
to call several method?
so use one which calls them all
function a(){
b();
c();
etc...
}
or maybe you want to capture the context of the filed?
please explain what you want to achive so i can help you.
Nushi.
to call several method?
so use one which calls them all
function a(){
b();
c();
etc...
}
or maybe you want to capture the context of the filed?
please explain what you want to achive so i can help you.
Nushi.
ASKER
I'm using JSP/Struts.
The page that is generate contains
text fields with associated hidden fields. When the text field changed the hidden field get status updated (onclick). When i press OK(onclick) the page is submitted. I can then see in my struts action which fields have a hidden field with value updated. So i only have to send the fields xith status updated to the DB.
The page that is generate contains
text fields with associated hidden fields. When the text field changed the hidden field get status updated (onclick). When i press OK(onclick) the page is submitted. I can then see in my struts action which fields have a hidden field with value updated. So i only have to send the fields xith status updated to the DB.
ok try this
<html>
<head>
<title>Untitled</title>
<script>
function gotoOK(){
alert("OK");
}
function doUpdate(){
alert("update");
gotoOK();
}
</script>
</head>
<body>
<input type=button name=okButton value="OK" onclick="doUpdate();gotoOK ()" >
<input type=text name=txtjkltest value="">
</body>
</html>
<html>
<head>
<title>Untitled</title>
<script>
function gotoOK(){
alert("OK");
}
function doUpdate(){
alert("update");
gotoOK();
}
</script>
</head>
<body>
<input type=button name=okButton value="OK" onclick="doUpdate();gotoOK
<input type=text name=txtjkltest value="">
</body>
</html>
ASKER
The first (onclick) should be (onchange) Sorry
doh...
and change this
input type=button name=okButton value="OK" onclick="doUpdate();gotoOK ()" >
to
input type=button name=okButton value="OK" onclick="doUpdate()" >
and change this
input type=button name=okButton value="OK" onclick="doUpdate();gotoOK
to
input type=button name=okButton value="OK" onclick="doUpdate()" >
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Jester_48
But i want to do first all my updates and then the submit.
I could keep the old values in hidden fields and then compare them in the doUpdate(). or just send everything then to the struts action and compare them there.If i do it like this your solution works. But was hoping i could do it without much changes to my code.
But i want to do first all my updates and then the submit.
I could keep the old values in hidden fields and then compare them in the doUpdate(). or just send everything then to the struts action and compare them there.If i do it like this your solution works. But was hoping i could do it without much changes to my code.
ASKER
Thanks Nushi,
I knew this should be simple :)) Your solution works.
Thanks everybody else for trying to help me.
Greetz,
Didier
I knew this should be simple :)) Your solution works.
Thanks everybody else for trying to help me.
Greetz,
Didier
>>Thanks Nushi,
>> I knew this should be simple :)) Your solution works.
even after you close this question im here to help you if you need something else regarding this.
P.S.
i hope its an A 9just for my record).
Thank you.
Nushi.
>> I knew this should be simple :)) Your solution works.
even after you close this question im here to help you if you need something else regarding this.
P.S.
i hope its an A 9just for my record).
Thank you.
Nushi.
:-))
Thank you.
Thank you.
<input type=text name=test value="" onblur="doUpdate()">
also the reason its happening is because the field has to loose focus before its considered "onchange"