jQuery method only seems to work once
When I click a title or subtitle, I want the corresponding radio button to display as selected. Right now, it only works the first time. Can someone show me where to fix it so it works on every click of the label? Thanks.
-
<div id="pageBanner">
<img id="logoImage" class="draggable" />
<div id="titleDiv" class="draggable"><label id="title">Team Title</label></div>
<div id="subtitleDiv"><label id="subtitle">Team subtitle that might be long</label></div>
</div>
<div id="editorSelection">
<h2>Select area to edit: </h2><br />
<input type="radio" name="areaToEditSelection" value="title" />Title
<input type="radio" name="areaToEditSelection" value="subtitle" />Subtitle
<input type="radio" name="areaToEditSelection" value="Logo" />Logo
</div>
- $(document).ready(function () {
- // Keep the value of the selected Div that is currently being worked with.
- // Default to title.
- var selectedLabelDivId = '#titleDiv';
- // Keep the value of the selected label that is currently being worked with.
- var selectedLabelId = '#title';
- getOriginialValues();
- // Original Attribute Values
- var originalLogoImageTop = $('#logoImage').css('top');
- var originalLogoImageLeft = $('#logoImage').css('left');
- // The size is the values of whichever control we are working with at the time (default is title).
- var originalSize;
- var originalTop;
- var originalLeft;
- var originalColor;
- var originalFont;
- var originalAlignment;
- $('#titleDiv').click(function () {
- // Set the radio buttons to the selected label that is currently being worked with.
- $('input:radio[name=areaToEditSelection]:nth(0)').attr('checked', true);
- // Set the currently selected label (title or subtitle).
- selectedLabelId = '#title';
- selectedLabelDivId = '#titleDiv';
-
- // Get the current values of the title or subtitle in case the user chooses to undo their changes.
- getOriginialValues();
- return false;
- });
- $('#subtitleDiv').click(function () {
- // Set the radio buttons to the selected label that is currently being worked with.
- $('input:radio[name=areaToEditSelection]:nth(1)').attr('checked', true);
- // Set the currently selected label (title or subtitle).
- selectedLabelId = '#subtitle';
- selectedLabelDivId = '#subtitleDiv';
-
- // Get the current values of the title or subtitle in case the user chooses to undo their changes.
- getOriginialValues();
- return false;
- });
- $('input[name=areaToEditSelection]').click(function () {
- selectedLabelDivId = '#' + $("input[name='areaToEditSelection']:checked").val() + 'Div';
- selectedLabelId = '#' + $("input[name='areaToEditSelection']:checked").val();
- });
- function getOriginialValues() {
- originalTop = $(selectedLabelDivId).css('top');
- originalLeft = $(selectedLabelDivId).css('left');
- originalAlignment = $(selectedLabelDivId).css('text-align');
- originalSize = $(selectedLabelId).css('font-size');
- originalColor = $(selectedLabelId).css('color');
- originalFont = $(selectedLabelId).css('font-family');
- var originalText = $(selectedLabelId).text();
- $('.hoverBox').initColor = originalColor;
- // Set the dropdown of type face fonts to the current type face, which defaults to Times New Roman if never selected.
- //$('#titleFontFamilySelector').val(originalFont);
- $("#titleFontFamilySelector option[value=" + originalFont + "]").attr("selected", "selected");
- // Put the value of the title/subtitle into the textbox so it can be edited.
- $('#titleInput').val(originalText);
- }
- });