Regex - Show selected option by URL parameter

0 votes
added Jul 3, 2018 in Regex by LC Marshal Captain (25,770 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 - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.