0

I have a web with an URL like that:

http://www.example.com/index.php?mod=7&sec=franquicias&month=10&year=2013

Inside, there is a date selector; which is supposed to change the get param month and year; and then reload the page.

From HTML, I do the following in the button in charge of decreasing the date:

<button type="button" class="btnIcon previous lbutton" onclick="changeMonth('previous',{$smarty.get.month},{$smarty.get.year})">

And the javascript function that has to manage with that is:

    function changeMonth(changeType, month, year){
    changeMonth;

    switch (changeType){
    case "previous":
        changeMonth = month-1;
        if (changeMonth <= 0) changeMonth = 12;
        if (changeMonth < 10) changeMonth = "0"+changeMonth;
        window.location = updateURLParameter($(location).attr('href'), month, changeMonth);
        break;
    case "next":
        break;
    }       
}

function updateURLParameter(url, param, paramVal){

    var regEx = /month=[0-9]{3}/;
    console.log("paramVal: "+paramVal);
            // paramVal here is ever correct.
    var newUrl = url.replace(regEx, 'month='+paramVal);

    console.log(newUrl);
    return newUrl;
}

It appears that it should work, now the strange thing is that only works when GET param in url is &month=03, when there are other month, url.replace doesn't replace the url correctly. It is important to note that 'paramVal' in function 'updateUrlParameter' it's always correct; so the problem it's in urlReplace from 'function updateUrlParameter'.

I appreciate any help.

2
  • try /month=[0-9]{1,3}/ Commented May 7, 2013 at 11:35
  • If I write /month=[0-9]{1,3}/ the page does not load...but you gave me the idea to try /month=[0-9]*/ and it's working; thank you. Commented May 7, 2013 at 11:57

1 Answer 1

1

I don't see how it can work even for month=03. [0-9]{3} matches exactly 3 digits, and 03 doesn't match that. The correct regexp is:

/\bmonth=\d{2}\b/
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.