LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   one charater is missed from html form field value (https://www.linuxquestions.org/questions/programming-9/one-charater-is-missed-from-html-form-field-value-548231/)

simon_qwl 04-23-2007 03:22 AM

one charater is missed from html form field value
 
hi,all
there is a very strong thing to me when i use javascript to get form field value.
the source code is as below:
Code:

document.myForm.content.value=document.myForm.message.value;
however, the "content" field always displays only the characters till the second last character from "message" field. For instance, the string typed in "message" field is abcd, then the string in "content" field is abc only.
Did this happen to anyone else? how did you solve this problem?
Thanks for any advices.

Guttorm 04-23-2007 07:04 AM

Hi

Strange thing yes, this should normally never happen. The only thing I can guess is that you are running that code in an "OnChange" event handler of the field name "message". Is that correct?

If so, I've seen similar things happen. The OnChange event handler is not run until the field loses focus or there is some other event happening. To test this, try to make third input field, bringing it to focus by clicking inside it should then update the "content" field correctly.

As for solutions, I think it's possible to add keyboard event handlers to the field, but it's not easy. A simpler way would be to use an "OnSubmit" handler on the form or something.

simon_qwl 04-24-2007 08:19 AM

Thank you very much for the hints. I finally solved the problem by creating another button to handle submission. Please note the button should be outside the form tag,for anyone encounter the same problem.


All times are GMT -5. The time now is 01:11 AM.