• Resolved cath_allen14

    (@cath_allen14)


    Hi,

    I have some radio buttons with images instead of text. When a user selects a radio button I would like to display the title of this image in a text field or calculated field.

    Is this possible?

    Thanks in advance!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @cath_allen14

    For example, assuming that the radio button field is the fieldname1, if you enter the title of the image as the corresponding choice’s value, the equation associated to the calculate field would be as simple as:

    
    fieldname1
    

    If you are talking about title attribute of the image tag, the equation would be a little more complex:

    
    (function(){
    var tmp = fieldname1;
    return jQuery('[id*="fieldname1_"]:checked').siblings('span').find('img').attr('title');
    })()
    

    Best regards.

    Thread Starter cath_allen14

    (@cath_allen14)

    Thanks – it would need to be the 2nd option and take the title tag of image as the value of the bullet poits would be a different price.

    I’ve added the code but it doesn’t seem to be working:

    http://ocnprt.com/q-stoneworks/quote/

    If I select the first or second bullet in the Granite Price Brand 1 box then the title text should appear in the ‘material name’ text box above but it doesn’t seem to be working.

    Any ideas? The bullet fieldname is <%fieldname19%>

    The code I used is:
    (function(){
    var tmp = fieldname19;
    return jQuery(‘[id*=”fieldname19_”]:checked’).siblings(‘span’).find(‘img’).attr(‘title’);
    })()

    Thanks in advance!

    Plugin Author codepeople

    (@codepeople)

    Hello @cath_allen14

    I’m sorry, my mistake. In the equations the texts with the format: fieldname# are replaced by the corresponding fields values, please, edit your equation as follows:

    
    (function(){
    var tmp = fieldname19;
    return jQuery('[id*="fieldname'+'19_"]:checked').siblings('span').find('img').attr('title');
    })()
    

    Note: I’ve checked the IMG tags on your form, and they don’t have associated a title attribute.

    Best regards.

    Thread Starter cath_allen14

    (@cath_allen14)

    Brilliant – thanks so much!

    One more thing (sorry to be a pain!) – if I have two sets of radio buttons fieldname19 and fieldname24 and want the title tag of both the selected images to appear in the text box, how would I adapt the above code for this?

    Thanks in advance!

    Plugin Author codepeople

    (@codepeople)

    Hello @cath_allen14

    Similar to:

    
    (function(){
    var tmp = fieldname19, tmp1 = fieldname24, result = '';
    
    result += jQuery('[id*="fieldname'+'19_"]:checked').siblings('span').find('img').attr('title');
    
    result += jQuery('[id*="fieldname'+'24_"]:checked').siblings('span').find('img').attr('title');
    
    return result;
    })()
    

    Best regards.

    Thread Starter cath_allen14

    (@cath_allen14)

    That works – thanks!

    Only one issue, when the page loads the material box now says ‘undefined’ until you select a radio button. How do I stop this?

    http://ocnprt.com/q-stoneworks/quote/

    Thanks in advance

    Plugin Author codepeople

    (@codepeople)

    Hello @cath_allen14

    Edit the equation as follows:

    
    (function(){
    var tmp = fieldname19, tmp1 = fieldname24, result = '';
    
    var f19 = jQuery('[id*="fieldname'+'19_"]:checked'),
    f24 = jQuery('[id*="fieldname'+'24_"]:checked');
    
    if(f19.length) result += f19.siblings('span').find('img').attr('title');
    if(f24.length) result += f24.siblings('span').find('img').attr('title');
    
    return result;
    })()
    

    and that’s all.
    Best regards.

    Thread Starter cath_allen14

    (@cath_allen14)

    Brilliant – thanks so much!

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Radio Button Image Title Attribute’ is closed to new replies.