The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> replace text in anchor text
Tiff 1998
post May 12 2017, 06:48 PM
Post #1





Group: Members
Posts: 5
Joined: 7-May 17
Member No.: 26,398



I have a list of movies that when the link has focus sends the link text to an input feild that I use for a search function.
I would like to do the same for tv shows.

My files are currently formatted as
CODE
<a href="showname s01e01.mp4">Showname s01e01</a>


The text I need to send to the input field is
Showname&Season=01&Episode=01

Is this possible without changing the link text that is displayed on the screen?

This is the script that I use to send the text to the input field.
CODE

$(function () {
    $('#rightbox a').on('focus', function () {
        var text = $('#moviename');
        text.val($(this).text());
var fileName =$(this).text();
        fileName = fileName.replace(/\.[^/.]+$/, "");
        text.val(fileName);    
        $Form.click();
    });
});


I'm guessing I need some regex in here, but I'm not good enough at regex yet.

This post has been edited by Tiff 1998: May 12 2017, 07:13 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
Tiff 1998
post May 16 2017, 06:53 AM
Post #2





Group: Members
Posts: 5
Joined: 7-May 17
Member No.: 26,398



Sorry Christian I got carried away and forgot to come back. I got it sorted out with this:

CODE

$("#rightbox a").focus(function() {
  var title = $(this).text(),
    isShow = (/s(\d+)e(\d+)/i).test(title),
    rgx, rplcment;

   rgx = (isShow) ? / s(\d+)e(\d+).*/i : /(\w+(\.\w+)*)\.\w+/;
  rplcmnt = (isShow) ? '&Season=$1&Episode=$2' : '$1';

  title = title.replace(rgx, rplcmnt);
  $('#moviename').val(title);
$Form.click();
});



Thank you for your time though smile.gif
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 20th April 2024 - 10:24 AM