Jump to content

Javascript (Jquery) Radio Button Value String Replace


aspacecodyssey

Recommended Posts

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?

	$(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');
			}
		});
	});

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.