/    Sign up×
Community /Pin to ProfileBookmark

Error when trying to show alert on submit (Jquery)

Hello.

I have this fiddle:

[url]https://jsfiddle.net/fqnsux89/7/[/url]

I am trying to show the user an error on the page (instead of the alert mentioned in the fiddle – which isn’t working).

Now I have to show user an error message when he tries to submit empty status.

What’s there in the code to be fixed?

Thanks in advance.

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumFeb 13.2016 — You didn't activate jQuery in your fiddle. And Submit obviously works only when it there is a form. This works:

https://jsfiddle.net/fqnsux89/13/

(Couldn't get the selector in the on-submit working.)
Copy linkTweet thisAlerts:
@osherdoauthorFeb 13.2016 — Hey thanks for helping out!

I have found another answer in another forum that might even improve the code you've provided me with:

https://jsfiddle.net/h13a8hmz/1/

Please let me know what you think please?

Thanks very much!
Copy linkTweet thisAlerts:
@SempervivumFeb 13.2016 — Yes, that's another approach that works. However I assumed that you intended to send the input to the server and therefore kept onsubmit.
Copy linkTweet thisAlerts:
@osherdoauthorFeb 14.2016 — I will keep the submit. Thanks for pointing that out to me.

The problem is that the alert is not showing when submitting an empty textbox.

https://jsfiddle.net/2rrbwsf1/1/

although not shown in this fiddle - the submit event does not throw anything in my browser (Opera ) but only in .on('click')

any idea what's wrong here?
Copy linkTweet thisAlerts:
@rootFeb 14.2016 — Please remember that we have a specific JQuery forum for JQuery questions.
Copy linkTweet thisAlerts:
@SempervivumFeb 14.2016 — Read my first answer:And Submit obviously works only when it there is a form. This works:

...

(Couldn't get the selector in the on-submit working.)[/QUOTE]


This works:

https://jsfiddle.net/2rrbwsf1/2/
Copy linkTweet thisAlerts:
@osherdoauthorFeb 14.2016 — Okay thanks for answering.

Is it okay I'll wrap only this div contenteditable textarea as form? It seems like the only option in this case. Don't know if it's the optimal one.
Copy linkTweet thisAlerts:
@SempervivumFeb 14.2016 — I don't understand completely what you intend to do. A div will not be automatically sent to the server on submit. You might have to transfer it's content to an invisible input or use a suitable input from the beginning.
Copy linkTweet thisAlerts:
@osherdoauthorFeb 14.2016 — It's like the status update text box in facebook. I will get the user's text and store it in the database. what would you suggest me to do?

should I wrap it with <form> tags? or there's a better practice?
Copy linkTweet thisAlerts:
@osherdoauthorFeb 14.2016 — It's like the status update text box in facebook. I will get the user's text and store it in the database. what would you suggest me to do?

should I wrap it with <form> tags? or there's a better practice?[/QUOTE]


the div has contenteditable area which is where I store the text.
Copy linkTweet thisAlerts:
@SempervivumFeb 14.2016 — Use an input tag of type text instead of a div and place it inside the form. This tag's content will be transmitted to the server on submit.
Copy linkTweet thisAlerts:
@osherdoauthorFeb 15.2016 — OK thanks really much for the help.
×

Success!

Help @osherdo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...