Skip to main content

Posts

Showing posts with the label Using Javascript

Check if the browser is safari using javascript

For checking if the browser is safari or not you can use below javascript function. function isSafari() {      var is_safari = navigator.userAgent.toLowerCase().indexOf('safari/') > -1;      if(is_safari)     {          return true;     }     else     {         return false;     } } The above method will return true or false depending on the browser. i.e.  if the browser is safari then the above method will return true and if it's not then the method will return false. Hope this will help :)

Get Selected value from Listbox Javascript

Since there is no direct way to get the selected value in the listbox you have to get it by iterating over the list.For same the code is given below. Below code will print all values in the listbox which were selected but you can modifiy the code as per your requirement. HTML code : <select id="listboxName"> <option value="1">One</option> <option value="2">Two</option> <option value="3">Three</option> </select> Javascript code : var mySelect = document.getElementById("listboxName"); for ( var i = 0 ; i < mySelect . options . length ; i ++) { if ( mySelect . options [ i ]. selected ) document . write ( " mySelect.options[i].text\n" ) } Hope this helps :)

Enabling/Disabling Textbox using JavaScript

Below is the example for enabling or disabling of the text box whose id is "testTextbox". HTML code of the text box <p>   <input type="text" id="testTextbox" ></input> </p> Javascript code for enabling the text box document.getElementById("testTextbox").disabled = false; Javascript code for disabling the text box document.getElementById("testTextbox").disabled = true; you can add the above javascript code in any of the javascript function you want and call it on some event or you can keep them disabled by keeping the input tags attribute to disabled like this they will always remain disabled and then you can enable them on some event