Log in

View Full Version : HTML Textarea AutoActive



queerfm
06-16-2008, 04:50 PM
Hi i am looking for way that when a user clicks this link


<a onclick=\"toggle('$SAM[sh_id]');parent.location='#SAM{$shouts[sh_id]}'\"><div class='reply'></div></a>";


I would like it to auto select this text area


<textarea name=minishout rows=4 onKeyDown=\"textCounter(this.form.message,this.form.remLen,300);\" onKeyUp=\"textCounter(this.form.minishout,this.form.remLen,300);\" style=\"width: 100%; height:50px;\">@{$SAM[login]}</textarea>


This is for the iPhone, i woudl basicly make it so that it allows a user to just start typing.

Any help would be great

Thanks

jscheuer1
06-17-2008, 06:22 AM
Without seeing your page, it would be difficult to supply the correct code. Here is a demo of the concept:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function setCursorPosition(oInput,oStart,oEnd) {
if( oInput.setSelectionRange ) {
oInput.setSelectionRange(oStart,oEnd);
}
else if( oInput.createTextRange ) {
var range = oInput.createTextRange();
range.collapse(true);
range.moveEnd('character',oEnd);
range.moveStart('character',oStart);
range.select();
}
}
window.onload = function(){
var ta = document.forms[0].elements['bob'];
ta.focus();
setCursorPosition(ta, ta.value.length, ta.value.length);
};
</script>
</head>
<body>
<form action="">
<textarea name="bob" cols="50" rows="5">Hi</textarea>
</form>
</body>
</html>

queerfm
06-17-2008, 04:12 PM
thanks that works well on firefox but not on the iPhone

jscheuer1
06-17-2008, 05:50 PM
I have no iPhone to test on, sorry.

It also works in IE, Opera, and Safari. It does require javascript enabled, perhaps the iPhone browser doesn't support javascript, or has only a limited subset of javascript, or your iPhone just has javascript disabled.

queerfm
06-17-2008, 09:16 PM
interesting i tested it in Safari and did not work... all i did was copy and past

jscheuer1
06-18-2008, 12:25 AM
I used Safari 3 Win. What did you use? Does it have javascript enabled? I did do some checking on the web about iPhone and javascript:

http://www.kudit.com/wiki/index.php/Javascript

and other similar sites. The iPhone is said to be limited to a degree as regards javascript, but I found nothing concrete either way about this particular code.

This might be especially helpful:

http://www.kudit.com/wiki/index.php/Copy_Paste