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 960135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:08:01+00:00 2026-05-16T01:08:01+00:00

I was recently berated by a fellow developer for using string math in an

  • 0

I was recently berated by a fellow developer for using “string math” in an app I wrote. I’m pretty new to the whole development thing, with no formal training, and I haven’t heard of this issue. What is it?

Code in question:

$('.submit-input').click( function() {
    var valid = true;
    $('input, select, radio').removeClass('error');
    $('.error-message').hide();

    $('.validate').each( function() {
        if($(this).val() == $(this).attr('default')){
            valid = false;
            $(this).addClass('error');
        }
    });

    if(!$('select[name="contact"] option:selected').val() != ''){
        $('select[name="contact"]').addClass('error');
        valid = false;
    }

    if(!$('input[name="ampm"]:checked').length){
        $('input[name="ampm"]').addClass('error');          
        valid = false;
    }

    if(!valid){
        $('.error-message').css('display','block');
        return false;
    } else {

        var services_selected = 'Services Selected: ';
        services_selected += $('.l3').text() + ', ' + $('.l4').text() + ', ' + $('.l5').text() + '; ' + $('.l6').text();
        var prices = 'Prices: ';
        prices += $('.l7').text() + ', ' + $('.l8').text() + ', ' + $('.l9').text() + ', ' + $('.l10').text();
        var name = 'Name: ';
        name += $('input[name="name"]').val();  
        var phone = 'Phone: ' 
        phone += $('input[name="phone"]').val();
        var time = 'Preferred contact time: ';
        time += $('select[name="contact"] option:selected').val() + $('input[name="ampm"]:checked').val();

        $.ajax({
            url: 'php/mailer.php',
            data: 'services_selected=' + services_selected +'&prices=' + prices + '&name=' + name + '&phone=' + phone + '&time=' + time,
            type: "POST",
            success: function() {
                $('#email_form_box .container').children().fadeOut(500, function() {
                    $('#email_form_box .container').html('<div style="margin:20px auto;text-align:center;width:200px;">yada yada yada<br /><span class="close">Close</span></div>');
                });
            }
        });
    }

});

Edit: The gist I’m getting here is that this isn’t a standard development colloquialism, and I should probably talk to the guy who gave me guff in the first place. So I’ll do that. Thanks guys. I’ll be back with an answer, or to check off whoever knew already.

  • 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-16T01:08:02+00:00Added an answer on May 16, 2026 at 1:08 am

    In most Javascript browser implementations, concatenating strings is slow due to excessive copying. See JavaScript: String Concatenation slow performance? Array.join('')?

    Preferred method is to use an array and join:

    var pieces = ["You purchased "];
    pieces.push(num, " widgets.");
    el.innerHTML = pieces.join('');
    

    Added more:

    I think you may have a lurking bug in your code: you don’t appear to be escaping your data values. If any of them include an ampersand, you’d be in trouble. Use escape() for all of your data values.

    ps. And this is a real bug that the other developer missed. The string math issue is a performance / maintainability issue.

    Added:

    I rewrote your email composition section (quickly). I think it’s cleaner (and will be slightly faster) when using a piece array.

    ....
    } else {
    
    var d = []; // the post_data pieces table
    
    d.push ('services_selected='); // Start the services_selected value
    d.push ('Services Selected: ');
    d.push ($('.l3').text(), ', ', $('.l4').text(), ', ', $('.l5').text(),
            '; ', $('.l6').text());
    
    d.push ('&prices='); // Start the prices value
    d.push ('Prices: ');
    d.push ($('.l7').text(), ', ', $('.l8').text(), ', ', $('.l9').text(),
            ', ', $('.l10').text());
    
    d.push ('&name='); // Start the name value
    d.push ('Name: ', $('input[name="name"]').val());
    
    d.push ('&phone='); // Start the phone value
    d.push ('Phone: ', $('input[name="phone"]').val());
    
    d.push ('&time='); // Start the timevalue
    d.push ('Preferred contact time: ',
            $('select[name="contact"] option:selected').val(),
            $('input[name="ampm"]:checked').val());
    
        $.ajax({
            url: 'php/mailer.php',
            data: d.join(''),
            type: "POST",
            success: function() {
                $('#email_form_box .container').children().fadeOut(500, function() {
                    $('#email_form_box .container').html('<div style="margin:20px auto;text-align:center;width:200px;">yada yada yada<br /><span class="close">Close</span></div>');
                });
            }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 474k
  • Answers 474k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all you need a sms-gateway or build one… May 16, 2026 at 4:13 am
  • Editorial Team
    Editorial Team added an answer short v = 0; for (unsigned int sample = 0;… May 16, 2026 at 4:13 am
  • Editorial Team
    Editorial Team added an answer using firebug, I added float:right; inside the div='tabs'.is this what… May 16, 2026 at 4:13 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.