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

  • SEARCH
  • Home
  • 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 3401300
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:59:54+00:00 2026-05-18T04:59:54+00:00

I have three form fields: name, first name, and lastname. The name field is

  • 0

I have three form fields: name, first name, and lastname. The name field is hidden and I’m trying to set the value to the firstname + lastname on keypress. I’m also trying to format it so that the characters are all lowercase and spaces are transformed into dashes.

So:

<input type="text" name="firstname" value="John John" />
<input type="text" name="lastname" value="Doe" />
<input type="hidden" name="name" value="john-john-doe" />

I’ve been trying to use the following code, but it’s not working…

            $('input[name=field_firstname[0][value]]').keyup(function() {
                    var firstname = $('input[name=field_firstname[0][value]]').val();
                    var lastname = $('input[name=field_lastname[0][value]]').val();
                    $('input[name=name]').val(firstname.replace(/\s/g, "-").toLowerCase()+lastname.replace(/\s/g, "-").toLowerCase());
            });

            $('input[name=field_lastname[0][value]]').keyup(function() {
                    var firstname = $('input[name=field_firstname[0][value]]').val();
                    var lastname = $('input[name=field_lastname[0][value]]').val();
                    $('input[name=name]').val(firstname.replace(/\s/g, "-").toLowerCase()+lastname.replace(/\s/g, "-").toLowerCase());
            });
  • 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-18T04:59:55+00:00Added an answer on May 18, 2026 at 4:59 am

    Perhaps I’m missing some context, but I don’t think you can use attribute selectors like that. To get at the firstname field, you’d say: input[name='firstname'].

    You’re also doing the same thing twice, which is always a good reason to give things some extra thought. For example, you can do both keyups in one shot:

    $("input[name='firstname'], input[name='lastname']").keyup(...);
    

    You can make things a lot easier by using IDs, though. For example, take this HTML:

    <input type="text" name="firstname" id="firstname" value="John John" />
    <input type="text" name="lastname" id="lastname" value="Doe" />
    <input type="hidden" name="name" id="sanitized_name" value="john-john-doe" />
    

    You’d use the following code snippit:

    $('#firstname, #lastname').keyup(function() {
      var fullname = $('#firstname').val() + ' ' + $('#lastname').val();
      $('#sanitized_name').val(fullname.replace(/\s/g, '-').toLowerCase());
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form with three fields Name, Email Address & Password. now i
We have a form that has fields for first and last name. I was
I have a form with 4 fields First Name (required) Last Name (required) Email
I have a form for a 'user profile' with the following fields: <form> First
e.g. we have form that ask for first name last name country, country is
Situation: you have a web page with a form that has a first name
I have a form that has multiple fields, and for testing purposes is there
I have an ASP.NET form with three text inputs, one each for Work Phone,
In VB.net 3.5 SP1 I have a Windows Form with three DataGridView controls. One
I have a UserControl that consists of three TextBoxes. On a form I can

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.