replace text in anchor text |
replace text in anchor text |
Tiff 1998 |
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 |
Tiff 1998 |
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 |
Lo-Fi Version | Time is now: 24th April 2024 - 05:18 AM |