473,569 Members | 2,845 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

adding onkeyup to input field

Lee
I have this function that doesn't work. I pass it the td element and
an id, and it makes an input field inside the td. That part workds.
What doesn't work is that I want to add an "onkeyup" on the input
field. Any help? Please??? I don't get any error on my javascript
console in firefox, and I am not seeing any errors in IE.

// makes an input field that submits itself using setCalendarValu e()
when it's blurred (it will be blurred if [enter] is pressed)
function makeCalendarInp utField(el,hour sId,which){
var id=el.id;

// if this input field is already active, then don't let it be
activated again
if(thisCalendar InputField==id) {
return false;
}
else{
thisCalendarInp utField=id;
}
var value = el.innerHTML;
// remember the original value just in case
originalValue=v alue;
el.innerHTML='' ;
var inputField = "<input type='text' value='" + value + "'
name='inputFiel d' id='inputField' "
+ " onBlur='setCale ndarValue(this, \"" + id + "\");'
class='calendar InputField' />"
+ "<input type='hidden' name='" + whichField + "' id='" +
whichField + "' value='" + which + "' />"
+ "<input type='hidden' name='" + hoursIdField + "' id='" +
hoursIdField + "' value='" + hoursId + "' />"
+ "";
// change the innerHTML of this td into this input field
el.innerHTML = inputField;
document.getEle mentById('input Field').focus() ;

el.onKeyUp="ale rt('hi')";

return;
}

Oct 20 '06 #1
13 14370
Lee wrote:
I have this function that doesn't work. I pass it the td element and
an id, and it makes an input field inside the td. That part workds.
What doesn't work is that I want to add an "onkeyup" on the input
field. Any help? Please??? I don't get any error on my javascript
console in firefox, and I am not seeing any errors in IE.

// makes an input field that submits itself using setCalendarValu e()
when it's blurred (it will be blurred if [enter] is pressed)
function makeCalendarInp utField(el,hour sId,which){
var id=el.id;

// if this input field is already active, then don't let it be
activated again
Do not allow posted code to auto-wrap, it nearly always introduces more
errors. Manually wrap code at about 70 characters and use 2 spaces for
indents, not tabs.

if(thisCalendar InputField==id) {
I guess the value of - thisCalendarInp utField - is set elsewhere.
return false;
}
else{
There is no need for an else after a conditional return.
thisCalendarInp utField=id;
}
var value = el.innerHTML;
// remember the original value just in case
originalValue=v alue;
el.innerHTML='' ;
var inputField = "<input type='text' value='" + value + "'
name='inputFiel d' id='inputField' "
+ " onBlur='setCale ndarValue(this, \"" + id + "\");'
class='calendar InputField' />"
The use of mixed-case attribute names in the source markup is a bad
habit, use all lower case (even though HTML doesn't care about case).

Your tag syntax indicates XHTML, but your attribute names appear to
require HTML. The use if innerHTML also infers the use of HTML (though
there is no standard to indicate whether that is a reasonable inference
or not).

Use HTML 4.01, there are no practical benefits to using XHTML on the
web.
+ "<input type='hidden' name='" + whichField + "' id='" +
whichField + "' value='" + which + "' />"
+ "<input type='hidden' name='" + hoursIdField + "' id='" +
hoursIdField + "' value='" + hoursId + "' />"
+ "";
// change the innerHTML of this td into this input field
el.innerHTML = inputField;
document.getEle mentById('input Field').focus() ;

el.onKeyUp="ale rt('hi')";
Javascript is case sensitive:

el.onkeyup = "alert('hi' )";

The use of all lower case attribute names (and tag names too) is a good
habit to get into, especially if you really do intend to use XHTML.
--
Rob

Oct 20 '06 #2
Lee
Do not allow posted code to auto-wrap, it nearly always introduces more
errors. Manually wrap code at about 70 characters and use 2 spaces for
indents, not tabs.
ok I hope I got it not wrapping, because I really do appreciate the
help. I've changed things as I've understood them (I really don't
understand XHTML/HTML, so I hope it's besides the point). After I
changed the function, it still works as always.

I realized I didn't use the correct element for "onkeyup," but it's
still not working. Still no javascript errors. Any further help is
really appreciated. Thanks on everything so far!

// makes an input field that submits itself using
// setCalendarValu e() when it's blurred (it will be blurred if [enter]
is pressed)
function makeCalendarInp utField(el,hour sId,which){
var id=el.id;

// if this input field is already active,
// then don't let it be activated again
if(thisCalendar InputField==id) {
return false;
}
thisCalendarInp utField=id;
var value = el.innerHTML;
// remember the original value just in case
originalValue=v alue;
el.innerHTML='' ;
var inputField =
"<input type='text' value='" + value
+ "' name='inputFiel d' id='inputField' "
+ " onblur='setCale ndarValue(this, \"" + id
+ "\");' class='calendar InputField' />"
+ "<input type='hidden' name='" + whichField
+ "' id='" + whichField + "' value='" + which + "' />"
+ "<input type='hidden' name='" + hoursIdField + "' id='"
+ hoursIdField + "' value='" + hoursId + "' />"
+ "";
// change the innerHTML of this td into this input field
el.innerHTML = inputField;

var inputEl=documen t.getElementByI d('inputField') ;
inputEl.focus() ;

inputEl.onkeyup = "alert('hi' )";

return;
}

Oct 20 '06 #3
Lee
By the way, I am going to use a separate library that adds onkeyup in
this fashion, and I'm just using alert to test things out in the
meantime. The library works perfectly elsewhere on an input field that
is already defined when the page loads.

Oct 20 '06 #4
ASM
Lee a écrit :
I have this function that doesn't work. I pass it the td element and
an id, and it makes an input field inside the td. That part workds.
What doesn't work is that I want to add an "onkeyup" on the input
field. Any help? Please??? I don't get any error on my javascript
console in firefox, and I am not seeing any errors in IE.
I do not understand,
you can add a onblur :
+ " onBlur='setCale ndarValue(this
and can't add a onkeyup ?

Why ?
In your function, from where comes 'thisCalendarIn putField' ?

It certainly would have been better to use createElement + appendChild
instead to use innerHTML ...

--
ASM
Oct 20 '06 #5
ASM
Lee a écrit :
I realized I didn't use the correct element for "onkeyup," but it's
still not working. Still no javascript errors. Any further help is
really appreciated. Thanks on everything so far!
....
function makeCalendarInp utField(el,hour sId,which){
var id=el.id;

// if this input field is already active,
// then don't let it be activated again
from where comes this 'thisCalendarIn putField' ?
what is it ?

if(!thisCalenda rInputField.dis abled)
{
thisCalendarInp utField.disable d=true;
return;
}
if(thisCalendar InputField==id) {
return false;
}
thisCalendarInp utField=id;
var value = el.innerHTML;
// remember the original value just in case
originalValue=v alue;
// variante :
while(el.firstC hild) el.removeChild( el.firstChild);
var field = document.create Element('input' );
field.name = 'inputField';
field.id = 'inputField';
field.onblur = function() { setCalendarValu e(this,'id'); }
el.appendChild( field);
field = document.create Element('input' );
field.name = whichField; // don't know from where 'whichField' comes
field.id = whichField;
field.value = which;
field.setAttrib ute = ('type', 'hidden');
el.appendChild( field);
field = document.create Element('input' );
field.type = 'hidden';
field.name = hoursIdField;
field.id = hoursIdField;
field.value = hoursId;
el.appendChild( field);
var inputEl=documen t.getElementByI d('inputField') ;
inputEl.focus() ;
inputEl.onkeyup = function() { alert('hi'); };
return;
}
Oct 20 '06 #6
Lee
Thanks, I think it will take me a little while to understand the child
functions and everything, but it looks like it might work.

On Oct 20, 10:24 am, ASM <stephanemoriau x.NoAd...@wanad oo.fr.invalid>
wrote:
Lee a écrit :
I realized I didn't use the correct element for "onkeyup," but it's
still not working. Still no javascript errors. Any further help is
really appreciated. Thanks on everything so far!
...
function makeCalendarInp utField(el,hour sId,which){
var id=el.id;
// if this input field is already active,
// then don't let it be activated againfrom where comes this 'thisCalendarIn putField' ?
what is it ?

if(!thisCalenda rInputField.dis abled)
{
thisCalendarInp utField.disable d=true;
return;
}
if(thisCalendar InputField==id) {
return false;
}
thisCalendarInp utField=id;
var value = el.innerHTML;
// remember the original value just in case
originalValue=v alue;// variante :
while(el.firstC hild) el.removeChild( el.firstChild);
var field = document.create Element('input' );
field.name = 'inputField';
field.id = 'inputField';
field.onblur = function() { setCalendarValu e(this,'id'); }
el.appendChild( field);
field = document.create Element('input' );
field.name = whichField; // don't know from where 'whichField' comes
field.id = whichField;
field.value = which;
field.setAttrib ute = ('type', 'hidden');
el.appendChild( field);
field = document.create Element('input' );
field.type = 'hidden';
field.name = hoursIdField;
field.id = hoursIdField;
field.value = hoursId;
el.appendChild( field);
var inputEl=documen t.getElementByI d('inputField') ;
inputEl.focus() ; inputEl.onkeyup = function() { alert('hi'); };
return;
}
Oct 21 '06 #7
ASM
Lee a écrit :
Thanks, I think it will take me a little while to understand the child
functions and everything, but it looks like it might work.
the important corrections where :
>field.onblur = function() { setCalendarValu e(this,'id'); }
and
>inputEl.onkeyu p = function() { alert('hi'); };
Oct 21 '06 #8
Lee
Thanks! But I'm so confused.
Why does this work
inputEl.onkeyup = function() { alert('hi'); };
instead of
inputEl.onkeyup ="alert('hi' )";

Also, I don't know if this will help me in the long run, since I'm
trying to use a library's class in order to do what I need. The syntax
will be: (and it works elsewhere)

var input=value;
var options2 = {
script:"employe eSuggestion.php ?",
varname:"input" ,
minchars:1
};
// add autosuggest
var inputFieldAs = new AutoSuggest(inp utEl.id, options2);

ASM wrote:
Lee a écrit :
Thanks, I think it will take me a little while to understand the child
functions and everything, but it looks like it might work.

the important corrections where :
field.onblur = function() { setCalendarValu e(this,'id'); }
and
inputEl.onkeyup = function() { alert('hi'); };
Oct 21 '06 #9
Lee
Actually in the object itself it's using that function technique... I
bet that the real problem arises because I am puting in the <input>
after the page loads. How do I manually insert it into the DOM? Do
you think this is really my problem?

Oct 21 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8839
by: Trent | last post by:
Hi. I know the basic way to assign event handlers: <input onKeyUp="processEvent(event)" /> But how do I assign a function to the onKeyUp event in *javascript* that can access the event object? // get inputElement alert("Some java script code"); inputElement.onkeyup = ????;
2
18437
by: Evan Wong | last post by:
I have problem to get onkeyup event. If we put the event in HTML statement like - "<input name=field1 size=16 onkeyup="javascript:function1();>" it works. If we put in JavaScript code like this var oElmt = document.createElement("input"); :
2
2892
by: john.lum | last post by:
My overall objective is to create something akin to Google Suggest, where a query is done in response to changes in a text field presented to the user. I've got things working using the onkeyup event and some AJAX techniques, but I am troubled by one thing: the more characters that are entered, the slower the interface is to settle down,...
2
10043
by: Robert Bravery | last post by:
HI all, I have a form for searches on a mysql database/table. The form has on input text box, and several pushbuttons. Depending on which pushbutton is selected, the search is then done on a specific field. One of them isa date field. How can I add or change the onfocus, onblur events of the input box to one that is relevant to the type of...
5
2235
by: Chris Lieb | last post by:
I am trying to add an event listener to the keyup event for some text inputs that I am creating dynamically. I have no problems getting it to work in Firefox, but IE just ignores them. I have created a few functions to aid in making this process work semi-cross-browser. (I develop in FF, but everyone who uses it will be using IE6.) ...
2
2182
by: Ken Fine | last post by:
In code, I'm adding javascript attributes to form elements on an ASP.NET page: body.Attributes.Add("onClick", "highlight(event);"); body.Attributes.Add("onKeyUp", "highlight(event);"); title.Attributes.Add("onClick", "highlight(event);"); title.Attributes.Add("onKeyUp", "highlight(event);"); description.Attributes.Add("onKeyUp",...
5
12562
by: J | last post by:
I am having problems dynamically adding more than one event handler to an input. I have tried the Javascript included at the bottom. The lines inp.attachEvent('onkeyup', makeEventFunc1(strand)); inp.attachEvent('onchange', makeEventFunc2(strand)); individually work in IE, but when used together, only the bottom one remains active. I...
6
5251
by: kodt | last post by:
I have a form with 4 text input fields. The last one is the total of the previous three fields and should automatically calculate this value when a user enters data into any of the first 3. Normally I would put an onkeyup="" event on the input elements and have that call the function. However, this form is automatically generated based upon...
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3637
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1209
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.