SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast robee's Avatar
    Join Date
    Aug 2003
    Location
    phils.
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation set cursor on the current position not at the end of text

    hi,

    im having problem with this javascript validator..it works anyway..here's the code.

    Code:
    var phone = "()- 0123456789";
    var numb = "0123456789";
    var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
    function valField(t,v){
    	var w = "";
    	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
    	if (keyCode == 37 || keyCode == 38 || keyCode == 39 || keyCode == 40) {
    	return true;
    	}
    	for (i=0; i < t.value.length; i++) {
    		x = t.value.charAt(i);
    		if (v.indexOf(x,0) != -1)
    		w += x;
    		}
    		t.value = w;
    	
    	
    		
    } 
    
    //here's how you call it in the form
    <input name="FIRM_NAME" type="text" onkeyup="valField(this,'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ,.\'()[]{}-/_+*&:;')" class="text_black" value="<%= FIRM_NAME %>" size="100" maxlength="100">
    but when I try to move my cursor in the middle of the text and say or type something..the cursor keeps on moving to the end of the string...how can i make the cursor not move to the end whenever i want to edit a text anywhere in the string? your help will be appreciated..thanks

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Which browser are you using? Some browsers automatically move you to the start or end of the field every time you call a validation routine that affects the field content.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Enthusiast robee's Avatar
    Join Date
    Aug 2003
    Location
    phils.
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im using IE 6... if so..is there a work around for this? im a bit frustrated whenever i want to edit a text in between and the cursor keeps on moving at the end of the string..

  4. #4
    SitePoint Enthusiast robee's Avatar
    Join Date
    Aug 2003
    Location
    phils.
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    up


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •