1

I'm trying to have inputs change the style of particular text and submit it to a filemaker server. Works great on IE but not on safari...

<select name="NameStyleFontName" id="'.$recordID2.'"  style="width:105px;"
fontatt="font-family" classid="stagename" onchange="fontupdate(this.id, this.name,
this.value, this.fontatt, this.classid)">

function fontupdate(id, name, value, att, cls)
{
    $('#loadres').html('<img src="loading.gif" />');
    $.post('fontupdate.php', {id: id, name: name, value: value})

    $('.'+cls).css(att, value); //this is where it fails.

    $('#loadres').html('<col />');
};

1 Answer 1

1

It probably doesn't work in anything but IE.

Most browsers don't support adding arbitrary attributes to the DOM. Since you're using jQuery, you should be able to get at them still using: $(this).attr('fontattr') instead of this.fontattr, but you should probably rethink the way you're doing this in the first place.

Or perhaps try using data-* attributes, which are an HTML5 feature, and intended for purposes like these. See http://html5doctor.com/html5-custom-data-attributes/

Sign up to request clarification or add additional context in comments.

3 Comments

function fontupdate() { var class = $(this).attr('rel'); var att = $(this).attr('fontatt'); $('.'+class).css(att, this.value); }; $('#NameStyleFontName').click(fontupdate);
No, $(this.attr('fontatt') would have to be passed as a parameter to fontupdate in the onchange. Or you could modify the fontupdate function definition to simply accept the element, i.e. function fontupdate(el) { and then onchange="fontupdate(this)". You could then use $(el).attr('fontatt') in your function body.
function fontupdate(el) { $('#loadres').html('<img src="loading.gif" />'); var att = $(el).attr('fontatt'); var cls = $(el).attr('classid'); var id = $(el).attr('id'); var name = $(el).attr('name'); var value = $(el).attr('value'); $.post('fontupdate.php', {id: id, name: name, value: value}) $('.'+cls).css(att, value); $('#loadres').html('<col />'); };

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.