Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

257
Vistas
i want to Set text-cursor to specific word(position given in below code) in a textarea?

My target is to click button and cursor will pop up on word assinged to given button. I have tried everything i can available online. but nothing worked. I'm in initial phase of learning javascript. I'm working on blog project and i need to insert extra code at this given postions thats why cursor need to set there. It will save time.

<script type="text/javascript">
function StringSearch(clicked_id) 
{
    if (clicked_id == 'top6-button-1') {
        var SearchTerm = 'item-1-end' ;
  //  block of code to be executed if condition1 is true
} else if (clicked_id == 'top6-button-2') {
    var SearchTerm = 'item-2-end' ;
  //  block of code to be executed if the condition1 is false and condition2 is true
} else if (clicked_id == 'top6-button-3') {
    var SearchTerm = 'item-3-end' ;
  //  block of code to be executed if the condition1 is false and condition2 is false
} else if (clicked_id == 'top6-button-4') {
    var SearchTerm = 'item-4-end' ;
    
} else if (clicked_id == 'top6-button-5') {
    var SearchTerm = 'item-5-end' ;
    
} else if (clicked_id == 'top6-button-6') {
    var SearchTerm = 'item-6-end' ;
    
} else {
    var SearchTerm = 'comparing-list-end' ;
}
    
    var TextSearch = document.getElementById("top6-initial-code").value;

     if (SearchTerm.length > 0 && TextSearch.indexOf(SearchTerm) > -1) {
         TextSearch.value = TextSearch.value + "\n";
  TextSearch.setSelectionRange(TextSearch.value.length, TextSearch.value.length);
  TextSearch.focus();
    
  } else {
    alert("No Data found in Text Area");
  }
}
</script>
<textarea name="top6-initial-code" id="top6-initial-code" cols="165" rows="40" value="all words i want to put cursor there in textbox, its too big">
<button type="button" id="top6-button-1" onclick="StringSearch(this.id)">Item 1</button>
<button type="button" id="top6-button-2" onclick="StringSearch(this.id)">Item 2</button>
<button type="button" id="top6-button-3" onclick="StringSearch(this.id)">Item 3</button>
<button type="button" id="top6-button-4" onclick="StringSearch(this.id)">Item 4</button>
<button type="button" id="top6-button-5" onclick="StringSearch(this.id)">Item 5</button>
<button type="button" id="top6-button-6" onclick="StringSearch(this.id)">Item 6</button>
<button type="button" id="top6-button-7" onclick="StringSearch(this.id)">Comparison</button>

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda