Firefox 4.01 ignoring everything after jQuery "event.preventDefault()" call in form element
I have a web page that dynamically generates form H开发者_开发百科TML via JavaScript and pours it into a div
with the id jobJSONConfigurationForm
.
To take over the form's Submit element (id jobJSONConfigurationFormSubmit
), I call the submit-div's live
function:
jobJSONConfigurationFormSubmit.live('click', function() {
event.preventDefault();
var jobSummaryJSONTextareaValue = $("#jobSummaryJSONTextarea").val();
var jobSummaryJSONObj = null;
try {
jobSummaryJSONObj = JSON.parse(jobSummaryJSONTextareaValue);
} catch(e) {
alert('This is not a valid JSON string. Please try again with a JSON-formatted string.');
}
updateJobSummaryWithJSONObj(jobSummaryJSONObj);
});
The updateJobSummaryWithJSONObj()
function updates the page's data model and the view (other forms and dynamically-generated HTML).
This code updates the model and view on Chrome 11 and 10, but this does not work on Firefox. The data model and view are not updated in Firefox 4.01.
If I add alert('foo')
before the event.preventDefault();
line, Firefox shows me the alert dialog box, but does not run the code in the rest of the function.
If I add alert('foo')
after the event.preventDefault();
line, Firefox does not show the alert or run the code in the rest of the function.
What am I doing wrong with jQuery under Firefox, which causes event.preventDefault()
to fail? Thanks for your advice.
event
is not defined automatically for a bound handler. It is the first argument. I think you meant:
jobJSONConfigurationFormSubmit.live('click', function(event) {
event.preventDefault();
...
Note: I'd also suggest using a name other than event
.
Judging from your code, event
isn't defined. Try jobJSONConfigurationFormSubmit.live('click', function(event) {
as line one. Hope that helps!
Try:
jobJSONConfigurationFormSubmit.live("click", function(evt) {
evt.preventDefault();
}
精彩评论