How to get the the value for a form element using JavaScript by ID

If you have a text input box with ID age and you want to obtain the value for the text box via JavaScript use the JavaScript function getElementById() to get the value Html input text box <input type="text" name="age" id="age" value="12" /> JavaScript function <script type="text/javascript"> var age = document.getElementById('age').value; </script>

March 21, 2018 · 1 min · 51 words · icarnaghan

How to get the value of a checked radio button in a group using JQuery

Within your JQuery code use the following line of code to get the value var radio_value = $("input[name='radio_group_name']:checked").val();

March 21, 2018 · 1 min · 18 words · icarnaghan

How to get the value of a radio button within a radio button group when selected using JQuery

Give all the radio buttons within a group the same name <input type="radio" name="RADIOGROUP" value="1" /> <input type="radio" name="RADIOGROUP" value="2" /> <input type="radio" name="RADIOGROUP" value="3" /> <input type="radio" name="RADIOGROUP" value="4" /> Now use the following JQuery code to obtain the value for the selected radio button within the Group $("input[name=RADIOGROUP]").change(function(){ alert($(this).val()); });

March 21, 2018 · 1 min · 52 words · icarnaghan

How to get the value of an HTML element by the attribute name instead of the attribute id using JQuery

This can be accomplished by using the name attribute selector $("input[name=ElementName]").val(); ElementName is the attribute name of the element <input type="text" name="ElementName" />

March 21, 2018 · 1 min · 23 words · icarnaghan

How to go back to the previous page with JavaScript

Use the history.go(-1) function in conjunction with the anchor html element Example <a href="javascript: history.go(-1);">Go back to previous page</a>

March 21, 2018 · 1 min · 19 words · icarnaghan

How to make a Textarea Read Only using JQuery

Use the following JQuery code $("input[name=postaddr], textarea").attr('readonly', 'readonly'); postaddr is the name of the textarea

March 21, 2018 · 1 min · 15 words · icarnaghan

How to redirect to a page using Javascript

window.location.href = 'redirect.html';

March 21, 2018 · 1 min · 3 words · icarnaghan

How to refresh an IFrame using Javascript

var iframe = document.getElementById('iframe_id'); iframe.src = iframe.src; iframe_id is the ID of the IFrame

March 21, 2018 · 1 min · 14 words · icarnaghan

How to remove a html table row using JQuery

Ensure that the html table row has an id e.g. <tr id="TABLE_ROW_ID"><td>I want to be removed</td></tr> Now the JQuery code that you will need to remove the table row $('#TABLE_ROW_ID').remove(); If you do not have an id for the table row, try using one of the JQuery selectors available here.

March 21, 2018 · 1 min · 50 words · icarnaghan

How to remove all options within a Html select box using JQuery

You have a html select box “combo box” <select id="selectBox"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> In order to remove all items using JQuery use the JQuery empty function $('#selectBox').empty(); Replace selectBox with the relevant id for the select box If you wish to empty the select box and add a single option to the select box, use JQuery’s append function together with the empty function $('#selectBox').empty().append('<option>New Option</option>'); This will add the New Option to the select box.

March 21, 2018 · 1 min · 77 words · icarnaghan