Help - Search - Members - Calendar
Full Version: replace text in anchor text
HTMLHelp Forums > Programming > Client-side Scripting
Tiff 1998
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.
Christian J
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".
Tiff 1998
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
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.