I have a short script written that works fine in Chrome:
function updateSentence(){ $(document).ready(function() { t = event.target.id; $("#S"+t).html($("#"+t).val()); }); }
However, in Firefox, the event is not defined. I found several similar questions that suggested that the event should be passed as a function parameter:
function updateSentence(event){ $(document).ready(function(event) { t = event.target.id; $("#S"+t).html($("#"+t).val()); }); }
However, for me, this solution does not fix the Firefox problem, and actually it breaks Chrome. In Chrome, it ends up event.target
not being detected when they are being transmitted.
What am I doing wrong?
After receiving a few comments, I realized that the way I thought about jQuery in general was wrong. I did not want $(document).ready
call every sentence update. Having cleared the function with this knowledge, I ended up:
function updateSentence(){ t = event.target.id; $("#S"+t).html($("#"+t).val()); }
This still correctly updates the sentence in Chrome, but target
remains undefined in Firefox. What do I need to do to get this working in Firefox? And am I still doing something fundamentally wrong in jQuery?
Also, to answer the question in the comments, the event I'm looking for is the onchange
event that caused updateSentence()
. This must be called when the select / text field changes.
(I'm still new to jQuery and JavaScript in general, and I'm sure I'm just making a simple mistake.)
I have found my answer. I will post in a couple of hours when the site allows me.