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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:07:56+00:00 2026-05-16T14:07:56+00:00

Forgive me if this is a stupid question; it’s been many years since I’ve

  • 0

Forgive me if this is a stupid question; it’s been many years since I’ve worked with javascript. This is actually javascript and html rendered via PHP in Joomla, but I’ve tried using the same code in a plain old local HTML file and I’m getting the same error. I have a select field with several options, and onchange I want to set the value of a text field to the value of the selected option. No matter which option I choose, the text field is being set to “undefined”. Can anyone help me out? Here’s the plain html code:

<html>
<head>
<script type="text/javascript">
function setPrefix(){
    var f = document.adminForm;
    f.prefix.value = f.editprefixes.selectedIndex.value;
}
</script>
</head>
<body>

<form name="adminForm">

<select name="editprefixes" onchange="javascript:setPrefix()">
<option value=1000>1000</option>
<option value=1001>1001</option>
<option value=1005>1005</option>
<option value=1011>1011</option>
<option value=1016>1016</option>
</select>
<br />

<input type="text" name="prefix" value="" />
</form>
</body>
</html>
  • 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-16T14:07:57+00:00Added an answer on May 16, 2026 at 2:07 pm

    A <select>‘s selectedIndex property does not refer to an actual <option> object, but rather is an integer corresponding to the index of the option that is selected (so the first option is 0, second is 1, and so on).

    If you want to get the value of the selected option, you need to use:

    var sel = f.editprefixes;
    f.prefix.value = sel.options[sel.selectedIndex].value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive me if this is a stupid question, I know there have been similar
Forgive me if this is a stupid question. I am not very experienced with
I'm kinda new to rails so forgive if this is a stupid question. The
I am a Scala novice so forgive me if this is a stupid question,
Forgive me if this is a particularly stupid question! mysql_query($query) returns a boolean, but
Forgive me if this is a really stupid question, but how do I get
Forgive me if this question is stupid, however what is the point of the
If this is a stupid question, forgive me, I'm not very familiar with PostgreSQL.
Forgive me if this is a stupid question. I'm a bit new to mobile
This may be a stupid question, but I'm still learning so do forgive me

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.