Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1928728
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T07:00:53+00:00 2026-05-17T07:00:53+00:00

When I click in field, type text, and press return on keyboard it triggers

  • 0

When I click in field, type text, and press return on keyboard it triggers the initializeTable function that refreshes page and gives error form[0] undefined. However, when I use change event to change dropdown selection, it doesn’t cause this unexpected behavior. So I’m not sure why pressing return key in text field is causing all this. Thanks for response.

<script>
(function($){

var listview = $('#listview');

var lists = (function(){
    var criteria = {
        dropFilter: {
            insert: function(value){
                if(value)

                    return {"filter" : value}; 
            },
            msg: "Filtering..."
        },
        searchFilter: {
            insert: function(value){
                if(value)
                    return {"search" : value}
            },
            msg: "Searching..."
        }

    }
    return { 
         create: function(component){
            var component = component.href.substring(component.href.lastIndexOf('#') + 1); //sites
            return component;
        },
         setDefaults: function(component){
            var parameter = {};
            switch(component){
                case "sites":
                    parameter = {
                        'url': 'sites',                         
                        'order': 'site_num',
                        'per_page': '20'
                    }
            }
            return parameter;
        },
        getCriteria: function(criterion){
            return criteria[criterion];    

        },
        addCriteria: function(criterion, method){
            criteria[criterion] = method;   
        }
    }
})();  

var Form = function(form){
    var fields = [];
    $(form[0].elements).each(function(){  
        var field = $(this);  
        if(typeof field.attr('alter-data') !== 'undefined') fields.push(new Field(field));  
    })  
}

Form.prototype = {
    initiate: function(){
        for(field in this.fields){
            this.fields[field].calculate();  
        }
    },
     isCalculable: function(){  
        for(field in this.fields){  
                if(!this.fields[field].alterData){ 
                return false; 
            }
        } 
        return true;  
    } 
}

var Field = function(field){ 
    this.field = field;  
    this.alterData = true;  
    this.component = {'url' : window.location.hash.substring(window.location.hash.indexOf('#') + 1)};
    this.attach("change");  
    this.attach("keypress");  
}

Field.prototype = { 
    attach: function(event){
        var obj = this; //our Field object
        if(event == "change"){
            obj.field.bind("change", function(){ 
                return obj.calculate();
            })
        }
        if(event == "keypress"){
            obj.field.bind("keypress", function(e){  
                var code = (e.keyCode ? e.keyCode : e.which);
                if(code == 13){ 
                    return obj.calculate();
                }
            })
        }
    },
    calculate: function(){
        var obj = this, 
            field = obj.field,  
            component = obj.component,
            msgClass = "msgClass",
            msgList = $(document.createElement("ul")).addClass("msgClass"),  
            types = field.attr("alter-data").split(" "),  
            container = field.parent(),  
            messages = [];

        field.next(".msgClass").remove();  
        for(var type in types){  
            var criterion = lists.getCriteria(types[type]);  
            if(field.val()){ 
                var result = criterion.insert(field.val()); 

                container.addClass("waitingMsg");  
                messages.push(criterion.msg);  

                obj.alterData = true;  

                initializeTable(component, result);  

            }
            else { 
                return false; 
                obj.alterData = false; 
            }
        }
        if(messages.length){
            for(msg in messages){
                msgList.append("<li>" + messages[msg] + "</li");  
            }
        }
        else{
            msgList.remove();  
        }
    }
}

$('#dashboard a').click(function(){
    var currentComponent = lists.create(this);
    var defaults = lists.setDefaults(currentComponent);
    initializeTable(defaults);
});

var initializeTable = function(defaults, custom){

    var custom = custom || {};

    var query_string = $.extend(defaults, custom);

    var params = [];
    $.each(query_string, function(key,value){
        params += key + '=' + value + "&"; 
    })
    var url = params.substring(params.indexOf("url")+4,9);
    params = params.substring(params.indexOf("&")+1).replace(params.substring(params.lastIndexOf("&")),"");

    $.ajax({
        type: 'GET',
        url: '/' + url,
        data: params,
        dataType: 'html',
        error: function(){},
        beforeSend: function(){},
        complete: function() {},
        success: function(response) { 
            listview.html(response);

                var form = $('form');
                form.calculation(); 


        }
    })


}

$.extend($.fn, {   
    calculation: function(){

            var formReady = new Form($(this));

            if(!formReady.isCalculable){
                return false; 
            }

    }
})

 })(jQuery)
 </script>

Rather than going through whole script, the actual issue is with this:

if(event == "keypress"){
            obj.field.bind("keypress", function(e){ 
                var code = (e.keyCode ? e.keyCode : e.which);
                if(code == 13){ 
                    return obj.calculate();
                }
            })
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T07:00:54+00:00Added an answer on May 17, 2026 at 7:00 am

    Finally, I got it to work this this:

                if(event == "keypress"){
                obj.field.bind("keypress", function(e){ 
                    var code = (e.keyCode ? e.keyCode : e.which);
                    if(code == 13){ 
                        e.preventDefault();
                        return obj.calculate();
                    }
                })
            }
        },
    

    Hence, we first prevent default and then execute our custom function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JTextField with some text. When I click text field the cursor
I am use a button and when u click this button a text field
If have an event that fires when a user clicks outside of text field,
I am using the Edit Text field in my application. when i click on
In the following example http://twitter.github.com/bootstrap/base-css.html#forms There is a text field with text Type something...
I need a field to store some information after one asp button click for
the order number of hidden field in grid view is 7. when i click
I was just wondering how to create an editText field on the click of
Backstory:I've created a tool to type in and press enter to add as many
<form id=form1 method = post> Text1:<input type =text id=textname1/><br> <input type =button name=button2 id=button2

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.