-1
<script type="text/javascript">
function setYear()
{

    var d = new Date(); 

    var cur = document.getElementById('CYear'); 
    var prev = document.getElementById('PYear'); 
    var next = document.getElementById('NYear'); 
    var optionC, optionP, optionN; 

    for (var i = d.getFullYear() - 10; i <= d.getFullYear() + 10; i++) 
    { 
        optionC = document.createElement("option"); 
        optionC.setAttribute("value", i); 
        optionC.innerHTML = i; 
        cur.appendChild(optionC); 
    };
    for (var i = d.getFullYear() - 10; i < d.getFullYear() + 10; i++) 
    { 
        optionP = document.createElement("option"); 
        optionP.setAttribute("value", i); 
        optionP.innerHTML = i; 
        prev.appendChild(optionP); 
    }; 
    for (var i = d.getFullYear() - 10; i <= d.getFullYear() + 10; i++) 
    { 
        optionN = document.createElement("option"); 
        optionN.setAttribute("value", i); 
        optionN.innerHTML = i; 
        next.appendChild(optionN); 
    }; 
    cur.value=d.getFullYear();
    prev.value=d.getFullYear()-1;
    next.value=d.getFullYear()+1;   
}
function setYear1(obj)
{
    var prev = document.getElementById('PYear');
    var next = document.getElementById('NYear');   
    
    prev.value = Number(obj.value) - 1;
    next.value = Number(obj.value) + 1;
}

function onlyNumbers(evt)
            {
                var evt = (evt) ? evt : event;
                var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
                if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode!=44)
                {
                    alert("Enter numerals only in this field!");
                    return false;
                }
                return true;
            }


</script>

I need to change this two function from JavaScript to jQuery. Are there any converters for doing this?

2
  • 2
    jQuery is a library/framework built on top of javascript - they aren't different languages. What exactly is it you need to change? Commented Aug 7, 2012 at 15:36
  • 2
    why do you need it to use jQuery? there's nothing wrong with plain javascript. in most cases, plain javascript is faster. Commented Aug 7, 2012 at 15:38

2 Answers 2

0

Adding jQuery to an existing project with JavaScript on it shouldn't break any existing JavaScript unless you're using a conflicting framework such as prototype, in which case you can often get away with both being present simply by setting jQuery to noConflict mode.

There's certainly no need to rewrite working JavaScript functions into jQuery if they're working fine as they are unless your primary goal is to improve efficiency / write shorter code or even if it's simply because the JavaScript has become too cumbersome to maintain.

In summary if you just want to add some new jQuery functionality to a website; why not just add it and leave the existing JavaScript as is?

https://stackoverflow.com/a/2305763/1188942


As for converters, I haven't been able to find any.

Sign up to request clarification or add additional context in comments.

Comments

0

jQuery is just an extension of javascript that deals (mostly) with selecting and manipulating DOM elements. So no, there isn't going to be a converter. I'd suggest actually learning jQuery -- it's unbelievably useful.

2 Comments

This is a comment, not an answer.
@Blazemonger technically it's an answer. The question is "how do I convert this to jQuery?" and the answer is essentially "you need to learn jQuery." And then there's the added bonus of explaining what jQuery is.

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.