Hi,
I have a text box to enter customer code and if i hit enter key should call the below fn to find the entered customer code.
..
....
function getKeyCode() {
var keyCode = window.event.keyCode;
if (keyCode == 13) {
var code = document.findForm.searchCust.value;
var url = '<%=request.getContextPath()%>';
url = url+"/custDisp.do?search=true&custCode="+code;
alert(url);
location.href = url1;
}
}
</script>
..
...
<input type=text name=searchCust onKeyPress="javascript:getKeyCode();return true">
..
...
But what happened means when i hit enter the url executed contains "http://custdev01:7001/PRO/customer/custDisp.do?searchCust=0280", instead of "http://custdev01:7001/PRO/customer/custDisp.do?search=true&custCode=0280". But the correct url is printed on alert box.
what is wrong with script?
Could someone help me to resolve this issue.
Advance Thanks.
Discussions
Web tier: servlets, JSP, Web frameworks: Hitting enter key should find text entered in text box.
-
Hitting enter key should find text entered in text box. (3 messages)
- Posted by: Kannan G
- Posted on: November 17 2005 17:31 EST
Threaded Messages (3)
- Hitting enter key should find text entered in text box. by Richard Merry on November 17 2005 18:49 EST
- Hitting enter key should find text entered in text box. by Kannan G on November 18 2005 10:00 EST
- Hitting enter key should find text entered in text box. by Srinath Anand on November 18 2005 12:58 EST
- Hitting enter key should find text entered in text box. by Kannan G on November 18 2005 10:00 EST
-
Hitting enter key should find text entered in text box.[ Go to top ]
- Posted by: Richard Merry
- Posted on: November 17 2005 18:49 EST
- in response to Kannan G
I'd say you need to escape the '&' in your URL, ie instead of
url = url+"/custDisp.do?search=true&custCode="+code;
try
url = url+"/custDisp.do?search=true&custCode="+code; -
Hitting enter key should find text entered in text box.[ Go to top ]
- Posted by: Kannan G
- Posted on: November 18 2005 10:00 EST
- in response to Richard Merry
Sorry Rich, it didn't work. Getting the same erroneous url executed. Is there anyother way, other than location.href, to execute the url.
Thanks -
Hitting enter key should find text entered in text box.[ Go to top ]
- Posted by: Srinath Anand
- Posted on: November 18 2005 12:58 EST
- in response to Kannan G
location.href = url1 but you are assigning url to the url you want to do to when enter is pressed. shouldn't the code read location.href = url;
also try using the escape function in javascript when dealing with & and other special character.