/    Sign up×
Community /Pin to ProfileBookmark

carriage return

Hey all,

I have this JS that is tied to a drop down list box using this :

[CODE]
onActivate=”soFar=”;” onKeyDown=”limitTo(this, this.form.arc);”
[/CODE]


what I am trying to do is make it to when the user hits the enter button (ascii 13?), the form will then postback

here is the js, any ideas?

[CODE]<script>
var soFar = “”;

function limitTo(sel, nextField)
{
var kc = window.event.keyCode;
// up down arrow keys
if ( kc == 40 || kc == 38 )
{
soFar = “”;
return;
}
// keyCode handler
window.event.cancelBubble = true;
window.event.returnValue = false;
//below is carriage return, line feed, tab
if ( kc == 10 || kc == 13 || kc == 9 )
{
nextField.focus();
return;
}
if ( kc == 8 )
{
if ( soFar.length > 0 ) soFar = soFar.substring( 0, soFar.length-1 );
} //below is the ascii for alpha/numeric + spacebar
else if ( kc < 32 || kc > 122 )
{
soFar = “”;
sel.selectedIndex = 0;
return;
}
else
{
soFar += String.fromCharCode(kc);
}

// now search for first match
var first = -1;

for ( var ix = 1; ix < sel.options.length; ++ix )
{
if ( soFar == sel.options[ix].text.toUpperCase().substring(0,soFar.length) )
{
first = ix;
break;
}
}
if ( first < 0 )
{
soFar = “”;
sel.selectedIndex = 0;
return;
}
sel.selectedIndex = first;

}
</script>[/CODE]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@LeeUOct 12.2007 — I believe this should do it:
[CODE]
onActivate="soFar='';" onKeyDown="[B]if(event.keyCode==13)[/B] limitTo(this, this.form.arc);"[/CODE]
Copy linkTweet thisAlerts:
@revkevauthorOct 12.2007 — unfortunately that was not it...

any other ideas?
Copy linkTweet thisAlerts:
@revkevauthorOct 13.2007 — anyone know how we can fix this???
Copy linkTweet thisAlerts:
@LeeUOct 15.2007 — Well, let's try this. Add this to the bottom of your main script:
[CODE]
function useEnter() {
if(event.keyCode==13) {
limitTo(this, this.form.arc)
}
}[/CODE]

Then, try this:
[CODE]
onActivate="soFar='';" onKeyDown="return useEnter;"[/CODE]

You might also try removing the "return" word.
×

Success!

Help @revkev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...