Are you first timer at Why not join us and start exchange your programming knowledge with everyone. Register today!

Regex - Show selected option by URL parameter

0 votes
added Jul 3, 2018 in Regex by LC Marshal Captain (25,840 points)
edited Jul 13, 2018 by LC Marshal
//example of URL parameter property.php?action=buy

//use this function to get the parameter value:
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(||[,""])[1].replace(/\+/g, '%20'))||null

//Then use the following method to set the value:
var val = getURLParameter('buy');
$('input#buy').val(val);   //  assign URL param to select field

Please log in or register to response this reference. - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.