Cursor at the begining of textarea on tab

<Script Language=JavaScript>

function setSelRange(inputEl, selStart, selEnd) {
if (inputEl.setSelectionRange) {
inputEl.focus();
inputEl.setSelectionRange(selStart, selEnd);
} else if (inputEl.createTextRange) {
var range = inputEl.createTextRange();
range.collapse(true);
range.moveEnd(‘character’, selEnd);
range.moveStart(‘character’, selStart);
range.select();
}
}
</script>

The above script sets the cursor position in the textarea at the begining of text. The textarea is already filled with text and I need to edit it, so I can start editing from the top. The scripts work fine.

<textarea rows=15 cols=100 name=‘POST’ onfocus=‘setSelRange(document.multiupdate.POST, 0, 0)’ />

The problem is that I have multiple textareas with names like POST[$i] in the same form. Multiple textarea being submitted to PHP script as an array. So now when I call the function in different textboxes, it doesn’t work.

<form name=multiupdate method=“POST”>

<textarea rows=15 cols=100 name=‘POST[0]’ onfocus=‘setSelRange(document.multiupdate.POST[0], 0, 0)’ />

<textarea rows=15 cols=100 name=‘POST[1]’ onfocus=‘setSelRange(document.multiupdate.POST[1], 0, 0)’ />

<textarea rows=15 cols=100 name=‘POST[2]’ onfocus=‘setSelRange(document.multiupdate.POST[2], 0, 0)’ />

How to overcome these textarea names with square brackets in it?

I am a complete newbie when it comes to javascript and have taken this function from another site.

Can someone please help?

That’s an option, but mixing markup and scripting behaviour is usually undesirable. And the form needs a block child.

hi,

create id attribute for textarea,
for example one, two, three.
Name is used only when you submit your data, and only fields which contains name will be submited to server. So you can use id instead, they must be different.

But also you can do it like this:

Example:

<form name=multiupdate method="POST">

<textarea rows=15 cols=100 name='POST[0]' onfocus='setSelRange(this, 0, 0)' />

<textarea rows=15 cols=100 name='POST[1]' onfocus='setSelRange(this, 0, 0)' />

<textarea rows=15 cols=100 name='POST[2]' onfocus='setSelRange(this, 0, 0)' />
</form>