Click to See Complete Forum and Search --> : converting a letter to an ascii value
damon2003
12-16-2003, 08:19 AM
hi,
is there a function to convert a letter of the alphabet to an ascii value and what is the definition of an ascii value, is it just a number?
thanks
haastnooit
12-16-2003, 08:41 AM
It is a coding scheme which assigns numeric
values to letters, numbers, punctuation marks, and other certain characters
such as control codes.
<SCRIPT LANGUAGE="JavaScript">
function showKeyCode()
{
var character = document.characterCode.character.value.substring(0,1);
var code = document.characterCode.character.value.charCodeAt(0);
var msg = "The ASCII Decimal Key Code for the \""+character+"\" character is "+code+".";
alert(msg);
}
</script>
<form name="characterCode">
<center>Type A Character:
<input type="text" name="character" size="15">
<input type="button" value="Show Key Code" onClick="showKeyCode();">
</center>
</form>
damon2003
12-16-2003, 10:34 AM
Hi
thanks that works good. However, I ran into another small problem because I found different value are given depending on the case of the variable
I have this:
var minLetter = (eval("document.form1."+hiddentextfieldMinRingSize+".value"));
var minLetterLower = minLetter.toLowerCase();
eval("document.form1."+hiddentextfieldMinRingSize+".value = "+ minLetterLower);
var minCode = (eval("document.form1."+hiddentextfieldMinRingSize+".value.charCodeAt(0)"));
I am dynamically creating the reference name of the hidden field.
The value in the field when I am testing is 'M', then I convert it to 'm'. I think it is the third line above, where there is a problem. When I try to set the hidden field value to m, it tells me 'm' is undefined
Anyway, it keeps telling me something is indefined. How can this be resolved,
thanks
fredmv
12-16-2003, 01:19 PM
Can we please see the rest of the code you are working with or possibly a link to the page?
damon2003
12-16-2003, 05:33 PM
Hi,
I have got it working a different, without having to reset the value of the hidden field,
//first store max value
var maxLetter = (eval("document.form1."+hiddentextfieldRingSizeIntialA+".value"));
maxLetter = maxLetter.toLowerCase();
maxLetter = maxLetter.charCodeAt(0)
//store actual value in ring size textfield
var actualLetter = (eval("document.form1."+textfieldRingSize+".value"));
actualLetter = actualLetter.toLowerCase();
actualLetter = actualLetter.charCodeAt(0)
if (actualLetter<minLetter)
{
returnVal = false;
alert("You have entered a ring size too low for this product");
}