Guest balboa Posted October 3, 2009 Share Posted October 3, 2009 hey,i need some help with textfield validating in AJAX. http://nitek.mine.nu:8080/balboa/webbprog/...ift1/uppg1.htmleverything works fine except when you leave a textfield that you wirtten something wrong and go to another text field by pressing it with your mouse pointer. The text "fel" disapears but i want it to stay. please help Link to comment Share on other sites More sharing options...
jeffman Posted October 3, 2009 Share Posted October 3, 2009 There are only two statements that set the text value to "". Each one occurs after an if(){} statement. Put an alert statement before each if(){} clause so you can see for yourself what the values are that you are testing. They might not be what you think.Hint 1: an <input> element does not have a .length property.Hint 2: it is not enough to test ajax.readyState == 4 . You should also test ajax.status == 200 . Other status values are possible when readyState==4. 4 simply means that a response was received, even if the response is an error message, like Error 500 or Error 203. So, for example, if your server script contains an parsing error or runtime error, ajax.responseText will not equal "fel" (even if the input would fail validation) and your script will fall into the else(){} clause.Hint 3: an inline event handler does not need "javascript:" in it. That construction is normally used when you want to include executable statements in the href property of an <a> element. (But this is not causing your problem.) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.