The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> 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
Christian J
post May 13 2017, 08:08 AM
Post #2


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(Tiff 1998 @ May 13 2017, 01:48 AM) *

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


As a sidenote, it's best not to use spaces in file names.

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

That looks like a URL querystring. Are the INPUT field values used to send database queries? In that case maybe there are better ways to create the whole application.

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

Maybe, but it's probably not simpler than changing the link text. You might use javascript split() and replace() and do something like:

1. Split "Showname s01e01" by the space, so you get "Showname" and "s01e01". This will fail if "Showname" itself contains spaces, though.
2. Split "s01e01" by the "e", so you get "s01" and "01".
4. In "s01", replace the "s" with "&Season=".
5. In "01", prepend "&Episode=".
6. Add it all together again after "Showname".
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Tiff 1998
post May 16 2017, 06:53 AM
Post #3





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

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: 28th March 2024 - 04:24 PM