Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
298 views
in Q2A Core by
I've written a custom js function to check input data in ask page. function checks whether there's question mark at the end of the sentence and so on... when user moves to next input field(by onBlur="" event)

I've added it to qa-ask.js file first, then to the ask page itself. But in both situations it isn't working. Why it isn't working???

 Code itself is fine. But it's not working when applied to q2a

function validateInput() {
  var val = document.getElementById("title");
  val.value.trim();
  len = val.value.length - 1;
  lastS = val.value.slice(len);
  if (lastS != "?") {
    document.getElementById("error").innerHTML = "add '?'.";
  .........

any help is appreciated
Q2A version: 1.7

1 Answer

0 votes
by
Your code is in a function but it's not clear exactly how you are calling the function.

Also, the getElementById("error") won't work because there is no such element by default, you'd need to create the element and add it to the DOM.
by
Actually i forgot to add that I added  <div id="error"> to  ask.php.
I think innerHTML is not working  in q2a.  
Then q2apro suggested
adding  ? mark automatically  
val.value += "?";
this worked. But I couldn't manage to  show error message using code above.
...