
IRCTC Form Autofill
- 2 minsJS file that can be run to fill IRCTC booking form and tremendously decrease the time it takes to fill the same manually
Setup
- Open
form-loader.js
file in any of the following recommended text editors:- vi or vim
- sublime text
- notepad++
- nano
- See for the
input
variable mentioned asvar input = { ... };
Fill it up with the required appropriate fields as mentioned in here.
- Open the page in IRCTC which asks for various details of passengers.
- Open Inspect Element or Developers Console in your browser and switch to
Console
tab - Paste the complete modified code present in
form-loader.js
in console and hit return key. - Voila! the fields are populated as per the inputs given by you.
Input Fields
- confirm_ticket_only - set this to
true
if you want to book ticket if it is confirmed. - auto_upgrade - set this to
true
if you want to use the Auto Upgradation facility provided by IRCTC - mobile_number - The mobile number to which notifications are to be sent
- persons - List of all the persons whose ticket is to be booked.
- name - The name of the person. Should be written within inverted commas.
- age - Age of the aforementioned person. Should be a number and not within inverted commas.
- gender - Either
1
or2
depending upon the person is Male or Female. Should be a number and not within inverted commas. - icard_type - Any number between
1
to9
according to the type of ID card number you want to enter. Should be a number and not within inverted commas. See this section for reference inform-loader.js
file:var field_values = { "icard_type": { ... } }
- icard_number - The ID card number. Should be written within inverted commas.
Code:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var form_fill = function() { | |
var input = { | |
"confirm_ticket_only": true, //if you want to book only confirmed tickets | |
"auto_upgrade": true, //if you want to use auto upgradation | |
"mobile_number": 9876543210, //Mobile number to which notication is to be sent | |
"persons": [ //details of each adult, max number is 4 | |
{ | |
"name": "Name 1", | |
"age": 0, | |
"gender": 1, | |
"icard_type": 2, | |
"icard_number": "########" | |
}, | |
{ | |
"name": "Name 2", | |
"age": 12, | |
"gender": 1, | |
"icard_type": 2, | |
"icard_number": "########" | |
} | |
//and so on if there are more person | |
] | |
}; | |
//Do not touch below this line if you are not a developer | |
var field_values = { | |
"icard_type": { | |
1: "DRIVING_LICENSE", | |
2: "PASSPORT", | |
3: "PANCARD", | |
4: "VOTER_ICARD", | |
5: "GOVT_ICARD", | |
6: "STUDENT_ICARD", | |
7: "BANK_PASSBOOK", | |
8: "CREDIT_CARD", | |
9: "UNIQUE_ICARD" | |
}, | |
"gender": { | |
1: "M", | |
2: "F" | |
} | |
}; | |
var input_fields = { | |
"name": ["text", "addPassengerForm\\:psdetail\\:{#}\\:psgnName"], | |
"age": ["text", "addPassengerForm\\:psdetail\\:{#}\\:psgnAge"], | |
"gender": ["list", "addPassengerForm\\:psdetail\\:{#}\\:psgnGender"], | |
"icard_type": ["list", "addPassengerForm\\:psdetail\\:{#}\\:idCardType"], | |
"icard_number": ["text", "addPassengerForm\\:psdetail\\:{#}\\:idCardNumber"], | |
"mobile_number": ["text", "addPassengerForm\\:mobileNo"], | |
"confirm_ticket_only": ["tick", "addPassengerForm\\:onlyConfirmBerths"], | |
"auto_upgrade": ["tick", "addPassengerForm\\:autoUpgrade"] | |
} | |
$.each(input, function(key, item) { | |
if (key === "persons") { | |
$.each(item, function(key, detail) { | |
$.each(detail, function(field, value) { | |
var type = input_fields[field][0]; | |
var id = "#" + input_fields[field][1].replace("{#}", key); | |
if (type === "text") { | |
$(id).val(value); | |
} else if (type === "list") { | |
value = field_values[field][value]; | |
$(id).val(value); | |
} else if (type === "tick") { | |
if (value === true) { | |
$(id).attr("checked", "checked"); | |
} else { | |
$(id).attr("checked", false); | |
} | |
} | |
}); | |
}); | |
} else { | |
var type = input_fields[key][0]; | |
var id = "#" + input_fields[key][1]; | |
if (type === "text") { | |
$(id).val(item); | |
} else if (type === "tick") { | |
if(item === true) { | |
$(id).attr("checked", "checked"); | |
} else { | |
$(id).attr("checked", false); | |
} | |
} else if (type === "list") { | |
var value = field_values[key][item]; | |
$(id).val(value); | |
} | |
} | |
}); | |
} | |
form_fill(); |
Source on Github : IRCTC Form Autofill
Please comment your views/suggestions below.