How to get URL parameter using jQuery or plain JavaScript?

Best solution here. var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = window.location.search.substring(1), sURLVariables = sPageURL.split(‘&’), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split(‘=’); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]); } } return false; }; And this is how you can use … Read more

How do you select a particular option in a SELECT element in jQuery?

A selector to get the middle option-element by value is $(‘.selDiv option[value=”SEL1″]’) For an index: $(‘.selDiv option:eq(1)’) For a known text: $(‘.selDiv option:contains(“Selection 1”)’) EDIT: As commented above the OP might have been after changing the selected item of the dropdown. In version 1.6 and higher the prop() method is recommended: $(‘.selDiv option:eq(1)’).prop(‘selected’, true) In … Read more

How to remove close button on the jQuery UI dialog?

I have found this worked in the end (note the third line overriding the open function which find the button and hides it): $(“#div2”).dialog({ closeOnEscape: false, open: function(event, ui) { $(“.ui-dialog-titlebar-close”, ui.dialog || ui).hide(); } }); To hide the close button on all dialogs you can use the following CSS too: .ui-dialog-titlebar-close { visibility: hidden; … Read more

How to break out of jQuery each loop?

To break a $.each or $(selector).each loop, you have to return false in the loop callback. Returning true skips to the next iteration, equivalent to a continue in a normal loop. $.each(array, function(key, value) { if(value === “foo”) { return false; // breaks } }); // or $(selector).each(function() { if (condition) { return false; } … Read more

Get selected element’s outer HTML

I believe that currently (5/1/2012), all major browsers support the outerHTML function. It seems to me that this snippet is sufficient. I personally would choose to memorize this: // Gives you the DOM element without the outside wrapper you want $(‘.classSelector’).html() // Gives you the outside wrapper as well only for the first element $(‘.classSelector’)[0].outerHTML … Read more

Prevent users from submitting a form by hitting Enter

You can use a method such as $(document).ready(function() { $(window).keydown(function(event){ if(event.keyCode == 13) { event.preventDefault(); return false; } }); }); In reading the comments on the original post, to make it more usable and allow people to press Enter if they have completed all the fields: function validationFunction() { $(‘input’).each(function() { … } if(good) { … Read more

jQuery get value of select onChange

Try this- $(‘select’).on(‘change’, function() { alert( this.value ); }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js”></script> <select> <option value=”1″>One</option> <option value=”2″>Two</option> </select> You can also reference with onchange event- function getval(sel) { alert(sel.value); } <select onchange=”getval(this);”> <option value=”1″>One</option> <option value=”2″>Two</option> </select>

How to allow only numeric (0-9) in HTML inputbox using jQuery?

Note: This is an updated answer. Comments below refer to an old version which messed around with keycodes. jQuery Try it yourself on JSFiddle. There is no native jQuery implementation for this, but you can filter the input values of a text <input> with the following inputFilter plugin (supports Copy+Paste, Drag+Drop, keyboard shortcuts, context menu … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)