aspacecodyssey Posted February 10, 2010 Share Posted February 10, 2010 Hey there, I've got standard select values in a form, and I'd like them each to show applicably titled div's (based on id) onclick. I don't want to have to specify which div should be shown when which option is chosen; I'd ratehr be able to use a string replace, i.e.: <input type="radio" name="project" value="Asphalt Paving Installation" />Asphalt Paving Installation<br /> <input type="radio" name="project" value="Asphalt Paving Repair or Patch" />Asphalt Paving Repair or Patch<br /> <input type="radio" name="project" value="Asphalt Seal Coating" />Asphalt Seal Coating<br /> <input type="radio" name="project" value="Excavating" />Excavating<br /> <input type="radio" name="project" value="Drainage" />Drainage<br /> <input type="radio" name="project" value="Masonry" />Masonry<br /> <input type="radio" name="project" value="Other" />Other<br /> So instead of basically saying "show this specific <div> if this specific radio button is selected, I'd like to be able to do this: <div id="Asphalt-Paving-Installation" class="hidden"> Stuff here </div> And something like: $(document).ready( function(){ $("input[name='project']").click(function(){ var project = $("input[name='project']:checked"); project.val( project.val().replace(' ','-') ); $("#"project.val()).show(); }); }); This way the div and the radio value can be the same (with the xception of the space/dash). Any ideas? Quote Link to comment Share on other sites More sharing options...
aspacecodyssey Posted February 10, 2010 Author Share Posted February 10, 2010 Got it! $(document).ready( function(){ $("input[name='project']").click(function(){ var project = $("input[name='project']:checked").val().replace(/ /g,'-'); $('#' + project).show(); }); }); Quote Link to comment Share on other sites More sharing options...
aspacecodyssey Posted February 11, 2010 Author Share Posted February 11, 2010 $(document).ready(function(){ $("input[type=checkbox]").click(function(){ project = $(this).attr("value").replace(/ /g,'-'); if ($(this).is(":checked")) { $("#" + project).show('fast'); } else if($(this).not(":checked")) { $("#" + project).hide('fast'); } }); }); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.