Problem in handling submit click in javascript namespace


I’m writing a function which needs to get the data from a textarea.
I’m trying to obtain its data by clicking on the form submit button.
The problem is that nothing happens when I click on it. It seems that my function doesn’t listen to it.
Can you help? Thanks!

here is the fiddle →

Two things to check.

First, jsfiddle doesn’t have a console to debug your code that way (although there is a workaround pointed by Wayne Koorts here), so for now I’d stick up with alert.

Second, when I accessed your fiddle, I had to manually add jQuery, because it wasn’t there by default, and since you are using jQuery, you might’ve missed that setting.

Now, to your code, I’m not sure why the button click is not triggering the function. I believe it’s because the purpose of the button is to submit the form, so there’s no click event bound to it (someone correct me if I’m wrong, please!). So if you select the form element, replace the click method with submit and alert the text variable value inside the function, you should get it!

I made a few changes and comment so you can guide yourself. Make sure to select a jQuery version and run the fiddle again:

Thanks, that helped a lot :smile:

One more thing. I’m trying to create a regular expression in order to check some text inserted in a textarea.
Basically, when I type I check the number of words inserted. Commas and full stop are allowoed. The problem is that when I type → word,another word my regex recognises only one word instead of two. I cannot find a good regex for it.

My current regex is → val.match(/\S+[A-Za-z]/g
What shall I add?

Thanks a lot!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.