prav, I'm curious...why did you pass window.event as a parameter?
Main Topics
Browse All TopicsI have a web form with several input text boxes. In some of the boxes I am looking for a dollar amount so I initialize the box with a '$' sign, adn another I want a percentage so i init the box with a '%' sign and another I want a web site so I init the box with "http://" . What I want to do is when the text box is selected I want the cursor to go to a specific location (either at the beginning for the percentage or at the end for the rest so the user does not erase the '$' or '%' or "http://" when entering in data.
Thanks,
JK
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
This is a nice script but what I was really looking for was a method to set the cursor position in the rext box when it's selected. Basically somehting likie this (but works):
function IsDollar(evt, textObj) {
textObj.CursorPosition = 2;
}
<input type="text" name="txt1" value="http://www.yahoo.co
You mean like this:
==========================
<html>
<head>
<title>Test Page</title>
<script language="JavaScript" type="text/javascript">
// From
// http://www.faqts.com/knowl
function setSelectionRange(input, selectionStart, selectionEnd)
{
if (input.setSelectionRange)
{
input.focus();
input.setSelectionRange(se
}
else if (input.createTextRange)
{
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character',
range.moveStart('character
range.select();
}
}
</script>
</head>
<body>
<form action="page.html" method="GET">
<input type="text" id="txt1" name="txt1" value="http://www.yahoo.co
</form>
</body>
</html>
Business Accounts
Answer for Membership
by: pravinasarPosted on 2005-10-25 at 13:25:35ID: 15157657
<script language="javascript"> ) == null) { textObj.value = '$' + textObj.value; } ) == null) { textObj.value = '%' + textObj.value; } ); vent, this);"> event, this);"> m" onKeyUp="IsHttp(window.eve nt, this);">
function IsDollar(evt, textObj) {
if (textObj.value.length < 0) { textObj.value = '$'; return; }
if (textObj.value.match(/^\$/
}
function IsPercent(evt, textObj) {
if (textObj.value.length < 0) { textObj.value = '%'; return; }
if (textObj.value.match(/^\%/
}
function IsHttp(evt, textObj) {
var str = "http://";
if (textObj.value.length < str.length) { textObj.value = str; return; }
var value = textObj.value.toLowerCase(
if (value.indexOf (str) < 0) { textObj.value = str + textObj.value; }
}
</script>
<input type="text" name="txt1" value="1213.0" onKeyUp="IsDollar(window.e
<input type="text" name="txt1" value="%11" onKeyUp="IsPercent(window.
<input type="text" name="txt1" value="http://www.yahoo.co