Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

263
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda