Advanced Javascript

They have: 330 posts

Joined: Apr 2000

I am trying to create a database of code snippets to help train co-workers on web design. I have a page that is database driven which displays all categories and then each subcategory under that.

example - Category is HTML, subcategory is Images.

Once the subcategory is clicked a view page is called which displays each record in the database associated with the subcategory. Each record consists of a header, comments, and an example which is populated into a textarea.

example - Subcategory is Images. Record 1 is Embed images. Record 2 is create hyperlink with image. Record 3 is create Image Map. etc.

Question #1 - On the AddInformation.asp page how would I make an onKeyDown script which converts all characters in the Header box to capital letters? I know I can do a UCase on the backend but I would rather the letter be capital when the user is entering them.

Question #2 - A majority of the code snippets will only be 1 line long but some of them (like javascript validation) will be a number of lines. I have written an asp script which will display 1 line if it's only 1 line but if it's more than that it only has 1 option which I have chosen to be 10 lines. I would like to make this more exact and kind of have an idea that should be possible. Please see below.

AddInformation.asp page -
Have a text box* (ReturnCount) populated with the number 0 and a textarea (Example) which is empty. When the user is populating the textarea (Example) there is an onKeyUp script which checks for the last key pressed. If it's a Chr(13) then it will add 1 to the ReturnCount.value. Is there a way to do that?

*When in production the text box will be a hidden field.

Thank you for any help.

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Use the toUpperCase() function is JS.

What is your header box? Is it a textarea/form element or just text?

The following code demonstrates how you can convert text in a textarea to capitals when the user presses any key anywhere on the page.

<body onKeyDown='document.all.txtArea1.value=document.all.txtArea1.value.toUpperCase()'>

<textarea name='txtArea1'>Test string. This will become upper case when you press any key.</textarea>

</body>
'

I haven't used the full DOM so this will only work in IE. Sticking out tongue Change it to fit with your code.

I probably didn't read carefully enough, so I'm yet unclear as to what you're trying to do with the other matters you referred to. Could you explain further? Laughing out loud

They have: 330 posts

Joined: Apr 2000

I went to Dell.com and found the toUpperCase and it is working fine. Thank you for that response though.

How would I write a javascript which will keep a running total of the number of times the Enter key is pressed in a textarea?

Thanks for any help?

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi artspimp,

This what you looking for?

<script>
val = 0;
function chkIt()
{
if (event.keyCode == 13)
{
val++;
alert(val)
}
}

</script>

Vinny

Where the world once stood
the blades of grass cut me still

They have: 330 posts

Joined: Apr 2000

Thank you. That definately resembles what I was looking for. Thank you.

Art

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi artsapimp,

you're welcome Laughing out loud

Vinny

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.