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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:37:40+00:00 2026-06-19T01:37:40+00:00

i am working on this project where i press a button that will look

  • 0

enter image description herei am working on this project where i press a button that will look for specific words in the textarea(may be move the cursor to that specific word). i tried many things but so far no luck.
here what i am trying to do.

$line ="<html>
<head>
<title>Drum studio home</title>
<body>
<img src="/images/fo.png" alt=""/>
</body>
</html> ";

the textArea is in php page, test.php

<textarea name="tvalue" id="tvalue">
                              <?php                                  
                                  echo $line . "\r\n";                                                                 
                              ?>
</textarea>
<input type="submit" value="find next" name="submit"/>

when i run test.php i will see the following inside the textarea.

<html>
<head>
<title>Drum studio home</title>
<body>
<img src="/images/fo.png" alt=""/>
<img src="/images/fo.png" alt="fo image"/>
</body>
</html> 

**find next**  --- this is the button

The find next button will find any image that has no alternative text.
I know i need js or jquery. I am new to this. so Don’t know really where to start. please help.
thanks

  • 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-19T01:37:41+00:00Added an answer on June 19, 2026 at 1:37 am

    Solution 1: Find next empty alt-attribute

    JavaScript

    function setSelectionRange(input, selectionStart, selectionEnd) {
      if (input.setSelectionRange) {
        input.focus();
        input.setSelectionRange(selectionStart, selectionEnd);
      }
      else if (input.createTextRange) {
        var range = input.createTextRange();
        range.collapse(true);
        range.moveEnd('character', selectionEnd);
        range.moveStart('character', selectionStart);
        range.select();
      }
    }
    
    function setCaretToPos (input, pos) {
      setSelectionRange(input, pos, pos);
    }
    
    function nextAlt(input) {
        pos = input.val().indexOf('alt=""');
        if (-1 == pos) {
            alert("None found");
        } else {
            setCaretToPos(input.get(0), pos);
        }
    }
    

    HTML

    <textarea id="textarea">
        Some sample text.
        <img src="" alt="">
        More text
        <img src="" alt="">
    </textarea>
    <br>
    <a onclick="nextAlt($('#textarea'));">Next</a>
    

    Demo

    http://jsfiddle.net/rMqbW/

    I’ve build this based on the accepted answer from this question:

    jQuery Set Cursor Position in Text Area

    Solution 2: Go through all HTML-tags

    This is the updated JavaScript to skip through all HTML opening tags. I only posted the updated/new parts.

    javaScript

    // new
    (function ($, undefined) {
        $.fn.getCursorPosition = function() {
            var el = $(this).get(0);
            var pos = 0;
            if('selectionStart' in el) {
                pos = el.selectionStart;
            } else if('selection' in document) {
                el.focus();
                var Sel = document.selection.createRange();
                var SelLength = document.selection.createRange().text.length;
                Sel.moveStart('character', -el.value.length);
                pos = Sel.text.length - SelLength;
            }
            return pos;
        }
    })(jQuery);
    
    // updated
    function nextAlt(input) {
        var current = input.getCursorPosition();
        var search = input.val().substr( ( 0 == current ? 0 : current + 1 ) );
        var pos = current + search.search(/<[a-zA-Z]+(>|.*?[^?]>)/) + 1;
        if (-1 == pos) {
            alert("No elements found");
        } else {
            setCaretToPos(input.get(0), pos);
        }
    }
    

    Demo

    http://jsfiddle.net/TmeV3/

    This one uses a solution from How can i get cursor position in a textarea? and a regex from Create a Javascript RegExp to find opening tags in HTML/php template.

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

Sidebar

Related Questions

I am working on a project in which one functionality is that this page
I'm working on a project that requires a button to only be pressed once
I'm working on a project that has a Main.fla and a Preload.fla. I am
I have a mvc 3 razor project that on pc is working very good
Basically I am supposed to press Command + the [`~] button that is above
When I create basic Android project on eclipse I can press debug button and
I have a group project for school that I am working on. A member
I'm working on a WPF project using Prism and MVVM, I'm new using this
I'm using Callback, on a asp.net webforms project. When clicked button, it is working
Good day, I've been working on this project and learning how to place a

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.