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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:29:51+00:00 2026-06-16T06:29:51+00:00

<select id="ddl_example4" name="ddl_example4"> <option value="1">item1</option> <option value="2">item2</option> <option value="3">item3</option> <option value="4">item4</option> <option value="5">item5</option> <option

  • 0
<select id="ddl_example4" name="ddl_example4">
<option value="1">item1</option>
<option value="2">item2</option>
<option value="3">item3</option>
<option value="4">item4</option>
<option value="5">item5</option>
<option value="6">item6</option>
</select>

</br>
<textarea rows="4" cols="50" id="tarea" onblur="myFunction()"></textarea>

<script>

function myFunction()
{

var x = document.getElementById("tarea");
iteminput = document.getElementById("ddl_example4");
var v = x.value.substring(5);
alert(v);

function setSelectedIndex(s, v) {
for ( var i = 0; i < s.options.length; i++ ) {
if ( s.options[i].text == v ) {
s.options[i].selected = true;
return;
}
}
}
}    
</script>

On blur, I’m able to get the value in alert box but I’m unable to get the same value selected in the drop down box. I copied the function setselectedindex from some other site.
Please let me know where I’m going wrong on this.

Is there a better way of achieving the same output using JavaScript?

  • 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-06-16T06:29:52+00:00Added an answer on June 16, 2026 at 6:29 am

    You included your setSelectedIndex function inside the myFunction function and you never actually called it.

    Try this:

    function myFunction()
    {
        var x = document.getElementById("tarea");
        iteminput = document.getElementById("ddl_example4");
        var v = x.value.substring(5);
        setSelectedIndex(iteminput, v);
    }    
    
    function setSelectedIndex(s, v) {
        for ( var i = 0; i < s.options.length; i++ ) {
            if ( s.options[i].text == v ) {
                s.options[i].selected = true;
                return;
            }
        }
    }
    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given following HTML <select name="IBE1$IBE_NurFlug1$ddl_Abflughafen" id="IBE1_IBE_NurFlug1_ddl_Abflughafen" class="dropdownlist" style="width: 99%;"> <option value="Antalya;TR">Antalya</option> <option value="Berlin;DE">Berlin</option> <option
Considering we have this HTML: <select id="my_select"> <option value="1">Foo</option> <option value="2">Bar</option> <option value="">Bork</option> <option
so i got this script for the moment : <select class="n-select" name="heure-event" id="heure-event"> <option
I have a select menu that looks like this: <select id ="cal-category-select"> <option value="/event-sort/list/2009/9/sports/">Sports
Say I have a dropdown list like this: <select id="MyDropDown"> <option value="0">Google</option> <option value="1">Bing</option>
<select name="select"> </select> I want to populate the above tag with values from database.
<xsl:call-template name="myfield"> <xsl:with-param name=A/> <xsl:with-param name=B/> <xsl:with-param name=C/> <xsl:if test="not(starts-with(specialTest))"> <xsl:with-param name="TEST" select="'someFunction'"/> </xsl:when>
Following is the part of my template that is having problem. <select id="country" name="country_id">
I know there is a very similiar question ( JavaScript: How to select "Cancel"
Given following Statment: String query = "Select * from T_spareParts where SparePartPK IN (?

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.