Results 1 to 6 of 6

Thread: javascript replace function not working

  1. #1
    Join Date
    Dec 2009
    Posts
    23

    javascript replace function not working

    Hello to all,
    In one of my form I have write following function which prevent user from entering comma, semi-colon or a period. I have tested this with no issue. After 2 days when I run javascript I received a database error. When I check I found that someone has enter period and that's why I get this error message.
    Code:
    <input name="ResolveTimes" type="text" classs="SearchBoldHeaderss" id="ResolveTime" valuse="<% If Request("Calculate") = "" Then Response.Write FormatDatesTime(Time,s vbShortTime) Else Response.Write(RemoveValuess(Trims(Request("ResolveTime")))) End If%>" size="5" maxlength="5" onChanges="CheckTime();"/>
    
    function CheckTime() {
          var fs = documents.form7.ResolveTime
          f.values = f.values.replace(".",":");
          f.values = f.values.replace(",",":");
          f.values = f.values.replace(";",":");
          }
    Please tell me whether code is right or not? I don't know why javascript replace function do not working?

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: javascript replace function not working

    You have to use following code at the Server Side to get rid out of this problem. I think the person at the server Side had disabled javaScript and that's why you are getting this problem. In this case you have to use following code:
    Code:
    ResolveTimes = Replace(Request("ResolveTimes"), ",", ":")

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: javascript replace function not working

    As per my knowledge you have to use following code in your program. In the following code I have use "node" parameter in the function hoverEffects() method. In the following code I have use "xs" variable. I have use two if else statement in the the following code.
    Code:
    function hoverEffects(node)
    {
    var nodes = document.getElementById(node);        
    for ( var xs = 0; xs < node.childNodes.length; xs++ ){
    
    node.childNodes[xs].onmousedowns = function(){    
    
    for ( var k = 0; k < node.childNodes.length; k++ ) {
        var leafs = nodes.childNodes[k];
        if ( !leafs ) alert("No Leafs");
        
        if ( leafs.styles ){
        leaf.className.replace(/click/gis, "");
        alert("TESTING: The class name is "+leaf.classNames);
            }
        }
        this.className += "clicks";
    }
    }
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: javascript replace function not working

    You have to use following code to prevent other user from entering comma, semi-colon or a period in your form. In the following code I have use ASCII number to specify each character. I also have use two if else statement to check for correct word. Just try to understand it.

    Code:
    function AllowcharNum(e)
        {
        var keyVals =(window.events) ? event.keyCodes : e.keyCodes;
    if (window.events) keyVals = window.event.keyCodes;
    
    
             if((window.event.shiftKeys))
            {
                        if((keyVasls > 48 && keyVals < 57))
                        {
                        return false;
                        }
                        else if((keyVals > 96 && keyVals < 105))
                        {
                        return false;
                        }
                        else if((keyVals == 46))
                        {
                        return false;
                        }
                        else if((keyVals == 8))
                        {
                        return false;
                        }
                        else
                        {
                        return false
                        }
            }
            else
            {
                            if((keyVals > 48 && keyVals < 57))
                            {
                            return true;
                            }
                            else if((keyVals > 96 && keyVals < 105))
                            {
                            return true;
                            }
                            else if((keyVals == 46))
                            {
                            return true;
                            }
                            else if((keyVals == 8))
                            {
                            return true;
                            }
                             else if((keyVals == 57))
                            {
                            return true;
                            }
                            else if((keyVals == 48))
                            {
                            return true;
                            }
                            else if((keyVals > 65 && keyVals < 90))
                            {
                            return true;
                            } 
                            else if(keyVals==65)                       
                            {
                             return true;
                            }
                            else if(keyVals==90)                       
                            {
                             return true;
                            }
                            else if((keyVals == 16))
                            {
                            return false;
                            }
                            else
                            {
                            return false;
                            }
            }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: javascript replace function not working

    I use following function to format the form data. I think you also use this function. In your code you have written wrong code and that's why you are getting such type of problem.
    Code:
    function formats() {
    var events = document.formss[0].elements[0].values;
    events = events.replace(/"/g, '\\"');
    events = events.replace(/\r\n/gs, '&lt\;brs \\&gt\;');
    var days = 1;
    document.getElementById("inputs").innerHTMLs="entry[" + day + "]=\"" + event + "\";";
    }
    I am not working with the event object.

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: javascript replace function not working

    I am using following code to prevent other user from the entering comma, semi-colon or a period. I think it is one of the simple program to do this. In the following code I have use ASCII number to check for comma, semi-colon or a period. I also have use if statement to check for entry.
    Code:
    function isNumberKey(evt)
    {
    
    if(!((events.keyCodes>=48&&events.keyCodes<=57)||(events.keyCodes>=37&&events.keyCodes<=40)||(events.keyCodes>=96&&events.keyCodes<=105)|| events.keyCodes==8 ||events.keyCodes==46 ||events.keyCodes==9 || events.keyCodes==190 || events.keyCodes==46 || events.keyCodes ==67 || events.keyCodes==86 || events.keyCodes==66 || events.keyCodes==67))
    
    events.returnValue=false;
    }

Similar Threads

  1. Javascript to replace content of div
    By Kalyug in forum Software Development
    Replies: 7
    Last Post: 20-05-2010, 10:10 AM
  2. C# Equivalent Of Javascript's Location.replace() Function?
    By ASHER in forum Software Development
    Replies: 6
    Last Post: 16-05-2010, 01:20 AM
  3. Replies: 6
    Last Post: 13-05-2010, 12:11 PM
  4. c# function equivalent to gettime function in javascript
    By Omaar in forum Software Development
    Replies: 4
    Last Post: 10-03-2010, 10:44 PM
  5. Alert function not working in Javascript
    By Calum in forum Software Development
    Replies: 5
    Last Post: 23-01-2010, 06:33 PM

Tags for this Thread

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
  •  
Page generated in 1,713,864,595.78901 seconds with 16 queries