• Our new ticketing site is now live! Using either this or the original site (both powered by TrainSplit) helps support the running of the forum with every ticket purchase! Find out more and ask any questions/give us feedback in this thread!

URL to Open Rail Planner Site to return next trains between two stations

Status
Not open for further replies.
Joined
1 Feb 2017
Messages
359
I’m putting together a web app (html pages that behave like a mobile phone app) as a project in my spare time for when I travel to certain places.

One feature I’m trying to implement is a button - that when you click it - loads up the NRE or similar site showing the next trains between two specified stations.

I know that NRE uses a structure in its urls with the two 3 letter station codes used - but I’m struggling to come up the link structure to open up the planner for the current day and not having to specify a date and time as it’ll be a static link.

Examples:

NRE - Sandwell to Worcester:
https://m.nationalrail. co.uk/pj/plan/SAD/WOF/230222/2135/dep

However that gives services on the 23rd departing 21:35

If I just have it set as:
https://m.nationalrail. co.uk/pj/plan/SAD/WOF/dep

It errors out and does not give the next services.

Anyone know of a way I can get the URL to play ball or can tell me of another planner site that would do this?
 
Sponsor Post - registered members do not see these adverts; click here to register, or click here to log in
R

RailUK Forums

blacklodge

Member
Joined
25 Feb 2019
Messages
8
This might help.

HTML:
<!doctype html>
<html class="no-js" lang="">

<head>
    <script
    src="https://code.jquery.com/jquery-3.6.0.js"
    integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk="
    crossorigin="anonymous"></script>
</head>

<body>


    <select id="settime" style="width:200px;" class="chzn-select" data-placeholder="Report Periode">
        <option value=""></option>
        <option value="1300">1300</option>
        <option value="1400">1400</option>
    </select>
    <select id="setorigin" name="selecttype" style="width:200px;" class="chzn-select" data-placeholder="Report Type">
        <option value=""></option>
        <option value="SAD">Sandwell & Dudley</option>
        <option value="WOF">Worcester Foregate Street</option>
        <option value="DWL">Dawlish</option>
        <option value="PAD">London Paddington</option>
    </select>
    <select id="setdest" name="selecttype" style="width:200px;" class="chzn-select" data-placeholder="Report Type">
        <option value=""></option>
        <option value="SAD">Sandwell & Dudley</option>
        <option value="WOF">Worcester Foregate Street</option>
        <option value="DWL">Dawlish</option>
        <option value="PAD">London Paddington</option>
    </select>
    <button class="go-btn" type="submit">Go</button>
    <script>
      $( document ).ready(function( $ ) {
    $( ".go-btn" ).click(function() {
        // Grab text from select boxes
        var time = $( "#settime option:selected" ).text();
        var origin = $( "#setorigin option:selected" ).text();
        var dest = $( "#setdest option:selected" ).text();

        // Set URL, change as necessary
        var url = "https://ojp.nationalrail.co.uk/service/timesandfares/" + origin + "/" + dest + "/today/" + time + "/dep";

        // Redirect
        window.location.href = url;
    });
});
    </script>
</body>

</html>
 

Pigeon

Member
Joined
8 Apr 2015
Messages
1,123
This might help.

Gaah, get rid of the bleeding jquery. Absolutely no need to haul in that massive great wad of guff, especially for something this simple. It's 282kB of wasted bandwidth and additional page load time.

Edit, tested, works:

HTML:
<!doctype html>
<html lang="">

<head>
    <script type="text/javascript">
      var go_button_click = function() {
        // Grab text from select boxes
        var time = document.getElementById("settime").value;
        var origin = document.getElementById("setorigin").value;
        var dest = document.getElementById("setdest").value;

        // Set URL, change as necessary
        var url = "http://ojp.nationalrail.co.uk/service/timesandfares/" + origin + "/" + dest + "/today/" + time + "/dep";

        // Redirect
        window.location.href = url;
    };
    </script>
    <style type="text/css">select { width: 200px; }</style>
</head>

<body>
    <select id="settime">
        <option value="1300">1300</option>
        <option value="1400">1400</option>
    </select>
    <select id="setorigin">
        <option value="SAD">Sandwell & Dudley</option>
        <option value="WOF">Worcester Foregate Street</option>
        <option value="DWL">Dawlish</option>
        <option value="PAD">London Paddington</option>
    </select>
    <select id="setdest">
        <option value="SAD">Sandwell & Dudley</option>
        <option value="WOF">Worcester Foregate Street</option>
        <option value="DWL">Dawlish</option>
        <option value="PAD">London Paddington</option>
    </select>
    <button id="go-btn" onclick="go_button_click();">Go</button>
</body>

</html>
 
Status
Not open for further replies.

Top