Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'd like to add the index of a given radio button to a URL string, but in the middle and have that passed to the value of a hidden input in a form.

here is the code so far:

jQuery

<script type='text/javascript'>//<![CDATA[ 
$(function(){
$('input[name="Names"]').click(function () {
var idx = $(this).index(':radio')
$('.submission input[name="image"]').val("http://URL/images/0 + (idx + 1) + .jpg");
})
});//]]>  
</script>

HTML

<div class="submission">
<input type="hidden" name="name" value="I'm Here Notification Sign" />
<input type="hidden" name="price" value="10" />
<input type="hidden" name="image" value="http://URL/images/01.jpg"/>
</div>

This obviously doesn't work, but for output i'd like to see http://URL/images/02.jpg when clicking on radio button 2 etc.

Thanks!

share|improve this question
    
What obviously doesn't work about it? –  isherwood Feb 13 at 19:44
1  
What rjreed said! Here's a fiddle: jsfiddle.net/Nz7Qz –  Jack Pattishall Jr. Feb 13 at 19:55
add comment

1 Answer

up vote 1 down vote accepted

This line needs to be:

$('.submission input[name="image"]').val("URL/images/0" + (idx + 1) + ".jpg"); 

You were passing one big string literal instead of concatenating them like you meant to.

share|improve this answer
1  
Also, you may need to coerce idx to a number to get it to add instead of concatenating: (+idx + 1) –  Tom Haws Feb 13 at 20:07
    
yep, that's it...just had the syntax wrong :-) Thanks guys! –  sventizzle Feb 13 at 21:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.