Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select option - replace & with regex

Tags:

jquery

regex

I am making an option select function that takes the add a unique dynamic url and replaces the

&

with

&

in the URL.

Jquery

$("#pageSizeOptions").change(function () {
   document.location.href = ('?ViewAction=View&ObjectID=1710211').replace(/(\?|&)(PageSize=[^&]+)(&|$)/, '$3') + $(this).val();
});

Perl Template (jquery)

$("#pageSizeOptions").change(function () {
   document.location.href = ('#Pager.URL').replace(/(\?|&)(PageSize=[^&]+)(&|$)/, '$3') + $(this).val();
});

OUTCOME:

http://fiddle.jshell.net/RFfXs/5/show/light/?ViewAction=View&ObjectID=1710211&PageSize=40

EXPECTED OUTCOME:

http://fiddle.jshell.net/RFfXs/5/show/light/?ViewAction=View&ObjectID=1710211&PageSize=40

http://jsfiddle.net/RFfXs/5/

Can anyone help on what exactly i am doing wrong..

like image 471
jagmitg Avatar asked Nov 12 '22 00:11

jagmitg


1 Answers

.replace(/&/g, '&')

http://jsfiddle.net/cP5Qs/

like image 183
A. Wolff Avatar answered Nov 15 '22 06:11

A. Wolff