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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:34:05+00:00 2026-05-12T09:34:05+00:00

This morning I asked a pretty mundane question about my JS syntax, and someone

  • 0

This morning I asked a pretty mundane question about my JS syntax, and someone suggested I use their code instead, so I went ahead with it because I know virtually Zero about JS.

Using my moderate PHP knowledge, I made a slight modification adding a second ID with an 'else if' statement (see below) and was just wondering if you folks who know more about JavaScript could tell me if it all looks good?

Or maybe you would do it differently altogether?

window.onload = formfocus;

function formfocus()
{
    var id_one;
    var id_two;

    id_one = document.getElementById( 'author' );
    id_two = document.getElementById( 's_primary' );

    if ( id_one )
    {
        id_one.focus();
        id_one.value = '';
    }
    else if ( id_two )
    {
        id_two.focus();
        id_two.value = '';
    }
}

EDIT: I am slightly concerned about my window.onload = formfocus(); … but not really sure if there is any other way to accomplish what I want.

  • 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-12T09:34:05+00:00Added an answer on May 12, 2026 at 9:34 am

    It could definitely be more terse, especially if you use jquery. But assuming you want to stick to plain old javascript, I’d at least change the following:

    var id_one;
    var id_two;
    
    id_one = document.getElementById( 'author' );
    id_two = document.getElementById( 's_primary' );
    

    to

    var id_one = document.getElementById( 'author' );
    var id_two = document.getElementById( 's_primary' );
    

    Also, it’s fairly standard practice not to surround function arguments with spaces, but I suppose that’s a style issue that shouldn’t be debated here.

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

Sidebar

Related Questions

I asked this morning a question about a jQuery code that's not working (which
So this morning I posted a confused question about assembly and I received some
This question is a folo to a previous question I asked about how to
So, I asked a question this morning, which I did not phrase correctly, so
[Hi, I asked this question in the morning but could not get any response
This morning, I read a very good question about what the person should expect
A customer has asked this morning why he isn't showing up at all in
This morning in my CS lab, I was compiling and executing some C code.
This morning we found an old chunk of code that was causing a library
this morning I came across this code, and I have absolutely no idea what

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.