How disable refresh when enter key pressed in the form input text?
-
Anybody knows how disable refresh when enter key pressed in the form input text in JavaScript? I have this JavaScript code
// JavaScript Document
function runScript(e){
if(e.keyCode == 13){
var div = document.createElement("div");
div.setAttribute("class", "resultItem");
var parentDiv = document.getElementById("result");
var input = document.getElementById("txtBox");
div.innerHTML = input.value;
parentDiv.appendChild(div);
}
}My HTML code:
Untitled Document
Website URL:
URL List
My problem is when everytime I hit enter on my keyboard it refresh the page. I want it in every enter the value in the text box will be displayed below the URL List. Any help will be appreciated
-
Anybody knows how disable refresh when enter key pressed in the form input text in JavaScript? I have this JavaScript code
// JavaScript Document
function runScript(e){
if(e.keyCode == 13){
var div = document.createElement("div");
div.setAttribute("class", "resultItem");
var parentDiv = document.getElementById("result");
var input = document.getElementById("txtBox");
div.innerHTML = input.value;
parentDiv.appendChild(div);
}
}My HTML code:
Untitled Document
Website URL:
URL List
My problem is when everytime I hit enter on my keyboard it refresh the page. I want it in every enter the value in the text box will be displayed below the URL List. Any help will be appreciated
hi,
flashery wrote:
<input id="txtBox" type="url" önKeyPress="return runScript(event)"/>
Try this one
<input id="txtBox" type="url" onkeydown="javascript:return runScript(event)" onkeypress="javascript:return false;"/>
-
hi,
flashery wrote:
<input id="txtBox" type="url" önKeyPress="return runScript(event)"/>
Try this one
<input id="txtBox" type="url" onkeydown="javascript:return runScript(event)" onkeypress="javascript:return false;"/>
-
I cant type anything on my textbox.. Maybe its because of this onkeypress="javascript:return false;"
may be for oncontextmenu: window.event.returnValue=false; // result not a return return false; // oncontextmenu may be visible so for other events may be too (ignore of return value). if possible .... read out an event if(window.event!=null) {X01=window.event; if(X01.srcElement!=null) {X02=X01.srcElement; d010[0]=X02; if(X02.tagName!=null){d010[1]=X02.tagName;} d010[2]=X01.returnValue; d010[3]=X01.type; d010[4]=X01.cancelBubble; d010[5]=X01.reason; d010[6]=X01.propertyName; X00=true; } } save cancelBubble i.e. fireEvent() set cancelBubble allways to false X03=window.event.cancelBubble; X04=document.createEventObject(); X02=X00.fireEvent(X01,X04); window.event.cancelBubble=X03; Syntax bFired = object.fireEvent(sEvent [, oEventObject]) Parameters sEvent Required. String that specifies the name of the event to fire. oEventObject Optional. Object that specifies the event object from which to obtain event object properties. erzeugt mit document.createEventObject() Return Value Boolean. Returns one of the following values: true Event fired successfully. false Event was cancelled function fnFireEvents() { oDiv.innerText = "The cursor has moved over me!"; oButton.fireEvent("onclick"); }
Using the fireEvent method
By moving the cursor over the DIV below, the button is clicked.
Mouse over this!
Button
-
may be for oncontextmenu: window.event.returnValue=false; // result not a return return false; // oncontextmenu may be visible so for other events may be too (ignore of return value). if possible .... read out an event if(window.event!=null) {X01=window.event; if(X01.srcElement!=null) {X02=X01.srcElement; d010[0]=X02; if(X02.tagName!=null){d010[1]=X02.tagName;} d010[2]=X01.returnValue; d010[3]=X01.type; d010[4]=X01.cancelBubble; d010[5]=X01.reason; d010[6]=X01.propertyName; X00=true; } } save cancelBubble i.e. fireEvent() set cancelBubble allways to false X03=window.event.cancelBubble; X04=document.createEventObject(); X02=X00.fireEvent(X01,X04); window.event.cancelBubble=X03; Syntax bFired = object.fireEvent(sEvent [, oEventObject]) Parameters sEvent Required. String that specifies the name of the event to fire. oEventObject Optional. Object that specifies the event object from which to obtain event object properties. erzeugt mit document.createEventObject() Return Value Boolean. Returns one of the following values: true Event fired successfully. false Event was cancelled function fnFireEvents() { oDiv.innerText = "The cursor has moved over me!"; oButton.fireEvent("onclick"); }
Using the fireEvent method
By moving the cursor over the DIV below, the button is clicked.
Mouse over this!
Button
Thanks man but this code is really to advance for me> I'm just learning JavaScript. But thanks anyway.. How about this code
function disableRefresh(e){
if(e.keyCode == 13){
return false;//some code follow here }
}
this makes the following code after
return false;
execute without refreshing the page and it work for me. My html textbox is look like this.
/form>
Correct me if I'm wrong cause this is the best and simple way for me to do this.
-
Thanks man but this code is really to advance for me> I'm just learning JavaScript. But thanks anyway.. How about this code
function disableRefresh(e){
if(e.keyCode == 13){
return false;//some code follow here }
}
this makes the following code after
return false;
execute without refreshing the page and it work for me. My html textbox is look like this.
/form>
Correct me if I'm wrong cause this is the best and simple way for me to do this.
-
disableRefresh(event) // param event must have type of object event // disableRefresh(this) give the pointer of INPUT that have an event like onkeypress
add a input type text belowe it. demo: u want disable refesh when enter key pressed on input name 'a'
Now u can press enter key and page will not reload