ASP.NET submit button not triggering after JavaScript function execution

I created a textbox with onpress and onblur events. The Javascript function will format the text to (xx-xxxxx).

<input type="text" id="txtnum"  
    onblur="javascript:return formatText(this)"  
    onkeypress="javascript:return formatText(this)">

Function formatText(elem)
{
    If(elem!=null)
    {
        Var str=elem.value;
        If(str.length==2)
        {
            Str=str+"-";
            Return true;
        }
    }
}

After entering a number like 12345678, it is formatted to 12-345678, but the submit button does not work.

If I only enter numbers, then the submit button works fine.

I even tried setting causes validation ="false", but that didn't resolve the issue.

Answer №1

Ensure the return statement is written outside of the if condition

if(str.length == 2) {
    str = str + "-";
}

return true;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for managing a web.config file in a multi-developer environment

Imagine having three different environments - dev, qa, and prod. On top of that, every developer has their own individual environment. How would you effectively manage the connection strings or app settings for each environment? It seems logical to use we ...

Activate Ajax functionality using a List of KeyValuePairs as a trigger

I am trying to make an AJAX call to a method that expects a List of key and value pairs, but I am struggling with the correct format. Here is what I have attempted so far: Server method: UpdateBranches(List<KeyValuePair<string, string>> bran ...

Texture spanning two sides

Currently tackling the challenge of creating a diamond shape with a unique texture. After successfully creating the desired geometry, I'm encountering difficulty in applying a texture to the diamond. The texture seems to be splitting on the face with ...

Activate or deactivate a button depending on the input value of a TextField in React.js

I am currently designing a form similar to the one displayed in this image. I want the "Add" button to become active as soon as the user starts typing in the "Tags" input field. For this project, I am using material-ui and I have created an Input compone ...

Using Electron with Angular 2 and integrating PouchDB

I'm currently exploring the use of Angular2, PouchDB, and Electron for my desktop application. However, I've hit a roadblock when trying to integrate the PouchDB APIs with Angular2. Could anyone provide guidance on how to utilize the PouchDB APIs ...

Utilizing conditionals for CSS minification with C# Regular Expressions

Hi there, I'm currently developing an application using C# in Visual Studio that focuses on minifying CSS code. Recently, I encountered a specific piece of code that removes all prefixes for the # ID selector. strCSS = Regex.Replace(strCSS, @"[a-zA-Z ...

Divide a picture with the help of javascript

Is there a way to utilize JavaScript to extract sections of an image and save them in an array, then showcase them randomly on an HTML5 canvas? ...

`The never-ending meteor cycle`

My goal is to modify the attributes of a Collection so that they have absolute positions before being rendered. I want the first item in the collection to have a top value of 0 and a left value of 0, the second item with a top of 0 and a left of 20, and so ...

Updating the minimum date based on the user's previous selection using React JS and Material UI

In my material UI, I have two date pickers set up: From Date - <KeyboardDatePicker value={initialDateFrom} disableFuture={true} onChange={handleFromDateChange} > </KeyboardDatePicker> To Date - <KeyboardDatePicker value={initialDateTo} ...

The power duo of JsonConvert and JArray is a force to

Utilizing the Last.FM audio scrobbler to identify the current song a user is playing: Encountering a formatting issue. When a user is currently playing a song, the result is formatted as: "recenttracks": { "track": [{ "artist": { ...

The qTip comment box vanishes when focused on by IE/Edge browsers using touch devices

A unique JavaScript library called qTip is being utilized in my project. The application includes a StarRating and Comments feature, both of which are enabled by this plugin. After selecting a rating using the stars, users have the option to add comments, ...

What is the best way to horizontally scroll and maintain the center alignment of a fixed-width div, especially when it exceeds the width of the browser window?

My current setup is almost perfect, but I am struggling to keep the green rectangle centered on the browser between 835px and 320px width. Any solutions using CSS or JavaScript are welcome. This is my first time posting a question on stackoverflow, so I h ...

"Struggling to make the 'overflow: hidden' property work for an absolutely positioned

I'm struggling to conceal an absolutely positioned image within a CSS grid layout. Below is the code snippet: HTML: <div class="relative-parent"> <div v-for="item in 12" class="hiding-parent"> <div c ...

Tips for incorporating XML data into HTML and jQuery

After generating an XML file from an Excel sheet, each item within the file follows a specific structure like this: <item> <partnum>pn0001</partnum> <category>Parent Category</category> <title>Item Name Here ...

Is there a way to troubleshoot and repair my SQLite query within my C# code?

I am struggling with a syntax error in my SQLite datagridview query. I am trying to fix the query but cannot seem to figure out what is causing the error. string command3 = ""; for (int y = year1; y <= year2; y++) { ...

React-Redux - Implement a button toggle functionality to display or hide additional information

I am currently working on creating a portfolio. One of the functionalities I am trying to implement is a toggle button that will show or hide the details of a specific work when clicked. I have been learning React and Redux, so this project is a great oppo ...

Find out which port is being utilized by a printing task

Currently, I am working on developing a print job monitoring system similar to the built-in Windows version. However, my main issue lies in not being able to extract specific details about the port on which the print job is printed. I have tried using bo ...

Assign authorization settings to a document when generating a new spreadsheet using the Google API

Using the Google Spreadsheets API in NodeJS, I successfully created a Spreadsheet with the code snippet below: const auth = new GoogleAuth({ keyFile: 'src/credentials.json', scopes: "https://www.googleapis.com/auth/spreadsheets" ...

Tips for dynamically loading fresh Google Adsense code with JavaScript without any user interaction

Recently, Google made a change in their ad code by replacing <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js</script> with <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygo ...

Is a finished callback needed for .on('xxx') event?

On my dashboard page, I am currently retrieving the top 25 comments and displaying them using the following code: fba.orderByChild('when').limitToLast(25).on('child_added', function (d, c) { stuff }); However, the function is called f ...