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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.