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

Regex - Show selected option by URL parameter

0 votes
51 views
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(location.search)||[,""])[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.

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...