Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to control cursor position in a textarea

Status
Not open for further replies.

sugermama

Technical User
Oct 19, 2001
11
US
Is there a way to control where the cursor appears in a textarea? Right now, when I click inside the textarea, the cursor appears in the middle of the first line. I am not sure whether this is an html or a javascript solution.

Thank you in advance for any assistance you might provide.
 
Hi,

I once had that problem and it turn out that there was an error in the html. Post your code so we can "investigate".

Bye.
 
I am using asp and connecting to a SQL database. Here is the html code for the form. If you need to see another part of the code please let me know. Thank you for your assistance.


<form id=&quot;frmAddLesson&quot; name=&quot;frmAddLesson&quot; action=&quot;add_lesson.asp&quot; method=&quot;POST&quot;>

<table width=&quot;100%&quot; border=1>
<tr>
<th colspan=&quot;6&quot;>Issue/Lesson Learned Information</th>
</tr>
<tr>
<td class=&quot;field&quot;>Issue/Lesson Learned:<br><font style=&quot;font-weight:bold&quot; size=&quot;-2&quot;>(Limit 5000 characters)</font>
</td>
<td><textarea name=&quot;strIssueLessonLearned&quot; rows=5 cols=35 maxlength=5000 wrap=&quot;physical&quot;>
</textarea></td>
</tr>
<tr>
<td class=&quot;field&quot;>Discussion:<br><font style=&quot;font-weight:bold&quot; size=&quot;-2&quot;>(Limit 5000 characters)</font>
</td>
<td><textarea name=&quot;strDiscussion&quot; rows=5 cols=35 maxlength=5000 wrap=&quot;physical&quot;>
</textarea></td>
</tr>
<tr>
<td class=&quot;field&quot;>Recommendation:<br><font style=&quot;font-weight:bold&quot; size=&quot;-2&quot;>(Limit 5000 characters)</font>
</td>
<td>
<textarea name=&quot;strRecommendation&quot; rows=5 cols=35 maxlength=5000 wrap=&quot;physical&quot;>
</textarea></td>
</tr>
<tr>
<td class=&quot;field&quot;>Division:
</td>
<td>
<Select NAME=&quot;Division&quot; onFocus=&quot;window.status='Division'&quot; onBlur=&quot;window.status=''&quot;>
<option>&lt;Choose One&gt;
<option value=Admin>Admin
<option value=Networks>Networks
<option value=R&S>R&S
<option value=StratComms>StratComms
<option value=Security>Security
<option value=IP>IP
<option value=PM>PM
<option value=XO>XO</select>
</FONT>
</TD>
</tr>
<tr>
<td class=&quot;field&quot;>Submitted By:
</td>
<td colspan=&quot;5&quot;>
<input type=text name=&quot;strSubmittedBy&quot; size=50 onChange=&quot;validate_name(this.form.strSubmittedBy)&quot;>
</td>
</tr>
<tr>
<td class=&quot;field&quot;>Phone Number:<br><font size=&quot;-2&quot;><i>XXX-XXX-XXXX
</td>
<td colspan=&quot;5&quot;>
<input type=text name=&quot;strPhone&quot; size=10>

</td>
</tr>


</table>
<br><hr><input type=submit value=&quot;Submit >>&quot;><input type=reset value=&quot;Reset &quot;>
</form>

 
Hi,

I now remember what causes this problem: remove everything between the two textarea tags ie: <textarea ...></textarea>
What you put in their shows up in the page, so if it contains a whitespace (tab, etc) it will cause the problem.

Bye.
 
I don't see anything that will occur that the cursor appears in the middle of the first line. I copied this code in my testpage and see 3 empty textarea's and when I click in it, the cursor start at the beginning. When I fill the textarea and than click the cursor appear where I click.

And I also don't understand what you said in your first post that it could be the javasript-solution. I don't see that you use some javascript to handle an event in the textarea (you only use some javscript to validate &quot;submitted by&quot;)

Do you use some more javscript? Let us know if you have more code.

By the way, here are some other tips:

1)<option>Choose One or <option value=Choose One>Choose One will show the words.

2) maxlength won't work for a textarea! You should test this with some client-side javascript or server-side ASP after your submit.

Erik
 
Read this post for a client-site maxlength solution.(read until the end because the first javasript solution is changed by another member later)

thread216-154360

Hope this helps,
Erik
 
yahve, I will try what you suggested. Boomerang, I will attach all of my code to this reply. Please remember that I am relatively new at this. I am still working on getting the validation to work, so my code may be choppy as it is still a work in progress.

Thank you for your help.

<!-- #include virtual=&quot;/scripts/header.asp&quot; -->

<Script Language=&quot;JavaScript&quot;>

function validateForm(form)
{
var why = &quot;&quot;;
why += validate_name(str.SubmittedBy.value);
why += validate_issue(str.IssueLessonLearned.value);
why += validate_division(choice.Division.value);
why += validate_phone(str.Phone.value);
why += validate_length(str.IssueLessonLearned.value, str.Discussion.value, str.Recommendation.value);
if (why != &quot;&quot;)
{
alert(why);
return false;
}
return true;
}



function validate_name(str)
{
if(str.SubmittedBy.value == &quot;&quot;)
{
alert(&quot;Please enter your name&quot;);
str.SubmittedBy.focus();
return false;
}
}

function validate_issue(str)
}
if(str.IssueLessonLearned.value == &quot;&quot;)
{
alert(&quot;Please enter an issue or lesson learned&quot;);
str.IssueLessonLearned.focus();
return false;
}
}

function validate_division(choice)
{
index = document.user_info.Division.SelectedIndex;

if (index == 0)
{
alert(&quot;Please select a division&quot;);
}
}


function validatePhone()
{
var telephone=document.frmAddLesson.strphone.value
if(telephone.match(/\d{10}/))
{
document.frmAddLesson.strphone.value=&quot;&quot; + telephone.substring(0,3) + &quot;-&quot;
+ telephone.substring(3,6) + &quot;-&quot;
+ telephone.substring(6,10)
}
else if(!telephone.match(/\d{3}(\s|-)\d{3}(\s|-)\d{4}/))
{
alert(&quot;Please enter a valid 10 digit phone number.&quot;)
document.frmAddLesson.strphone.value=&quot;&quot;
document.frmAddLesson.strphone.focus();
document.frmAddLesson.strphone.select();
return false;
}
}



function validate_length(str)
{

var maxlength=5000
if (cur.chars.value.length>maxlength){
alert(&quot;Please restrain your input to 5000 or less characters!&quot;)
return false;
}



</script>



<%
Dim LESSONS_LEARNED, strLessonID, strIssueLessonLearned, strDiscussion
Dim strRecommendation, strDivision, strSubmittedBy, strPhone
%>



<BODY BGCOLOR=WHITE LINK=&quot;#192A60&quot; VLINK=&quot;#304385&quot;>
<% Select Case Request.ServerVariables(&quot;REQUEST_METHOD&quot;) %>
<% Case &quot;POST&quot;

strIssueLessonLearned = Trim(request.form(&quot;strIssueLessonLearned&quot;))
strDiscussion = Trim(request.form(&quot;strDiscussion&quot;))
strRecommendation = Trim(request.form(&quot;strRecommendation&quot;))
strDivision = Trim(request.form(&quot;strDivision&quot;))
strSubmittedBy = Trim(request.form(&quot;strSubmittedBy&quot;))
strPhone = Trim(request.form(&quot;strPhone&quot;))

'strSQL = &quot;SELECT * from LESSONS_LEARNED ORDER BY LessonID&quot;
'DBGetRecords(strSQL)

sSQL = &quot;INSERT INTO LESSONS_LEARNED (IssueLessonLearned, Discussion, Recommendation, Division, SubmittedBy, Phone) VALUES ('&quot; & strIssueLessonLearned & &quot;','&quot; & strDiscussion & &quot;','&quot; & strRecommendation & &quot;','&quot; & strDivision & &quot;','&quot; & strSubmittedBy & &quot;','&quot; & strPhone & &quot;')&quot;
oRecordSet = oConnection.Execute( sSQL )

%>

<h2>Thank-you for submitting your Issue/Lesson Learned. You can view all submitted Issues and Lessons Learned by clicking on the link below.</h2>


<br><br>
<a href=&quot;add_lesson.asp&quot;>Return to Add Issue/Lesson Learned Form</a><br>
<a href=&quot;ll_results.asp&quot;>View all Lessons Learned</a>

<% Case Else %>

<!-- Body Begins Here -->


<TABLE BORDER=0 CELLPADDING=10>

<TD WIDTH=&quot;90%&quot;>

<p align=&quot;left&quot;><b>Complete the form below and click the Submit button to add an Issue/Lesson Learned to the database</b></p>

<form id=&quot;frmAddLesson&quot; name=&quot;frmAddLesson&quot; action=&quot;add_lesson.asp&quot; method=&quot;POST&quot; onSubmit=return(validateForm.this>

<table width=&quot;100%&quot; border=1>
<tr>
<th colspan=&quot;6&quot;>Issue/Lesson Learned Information</th>
</tr>
<tr>
<td class=&quot;field&quot;>Issue/Lesson Learned:<br><font style=&quot;font-weight:bold&quot; size=&quot;-2&quot;>(Limit 5000 characters)</font>
</td>
<td><textarea name=&quot;strIssueLessonLearned&quot; rows=5 cols=35 maxlength=5000 wrap=&quot;physical&quot;>
</textarea></td>
</tr>
<tr>
<td class=&quot;field&quot;>Discussion:<br><font style=&quot;font-weight:bold&quot; size=&quot;-2&quot;>(Limit 5000 characters)</font>
</td>
<td><textarea name=&quot;strDiscussion&quot; rows=5 cols=35 maxlength=5000 wrap=&quot;physical&quot;>
</textarea></td>
</tr>
<tr>
<td class=&quot;field&quot;>Recommendation:<br><font style=&quot;font-weight:bold&quot; size=&quot;-2&quot;>(Limit 5000 characters)</font>
</td>
<td>
<textarea name=&quot;strRecommendation&quot; rows=5 cols=35 maxlength=5000 wrap=&quot;physical&quot;>
</textarea></td>
</tr>
<tr>
<td class=&quot;field&quot;>Division:
</td>
<td>
<Select NAME=&quot;Division&quot; onFocus=&quot;window.status='Division'&quot; onBlur=&quot;window.status=''&quot;>
<option>&lt;Choose One&gt;
<option value=Admin>Admin
<option value=Networks>Networks
<option value=R&S>R&S
<option value=StratComms>StratComms
<option value=Security>Security
<option value=IP>IP
<option value=PM>PM
<option value=XO>XO</select>
</FONT>
</TD>
</tr>
<tr>
<td class=&quot;field&quot;>Submitted By:
</td>
<td colspan=&quot;5&quot;>
<input type=text name=&quot;strSubmittedBy&quot; size=50 onChange=&quot;validate_name(this.form.strSubmittedBy)&quot;>
</td>
</tr>
<tr>
<td class=&quot;field&quot;>Phone Number:<br><font size=&quot;-2&quot;><i>XXX-XXX-XXXX
</td>
<td colspan=&quot;5&quot;>
<input type=text name=&quot;strPhone&quot; size=10>

</td>
</tr>


</table>
<br><hr><input type=submit value=&quot;Submit >>&quot;><input type=reset value=&quot;Reset &quot;>
</form>

<br><br>
<a href=&quot;ll_results.asp&quot;>View all Lessons Learned</a>

<!-- End Body -->

</TR>
</TABLE>


<% End Select %>
<!-- Body Ends Here -->
<!-- #include virtual=&quot;/scripts/footer.asp&quot; -->
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top