0

I have a form in a JSP as follows:

<form action = "<c:url value = '/displayVisualisation' />" 
    title = "${item.visDescription}" 
    method = "post" onClick = "return confirmRequest('Do you want to change  to
        another visualisation type?');">                       
    <input class = "text" type = "text" value = "${item.visTypeName}"> 

</form>  

Which calls a Javascript method as follows:

function confirmRequest(questionText) {
    var confirmRequest = confirm(questionText);   
    if (confirmRequest) {
        return true;
    }

    else {
        return false;
    }                    
}

To ask the user for a reply to the question asked. However, the confirm prompt appears but does not perform the displayVisualisation action!

Can anyone suggest why or help me implement this correctly?

In other examples, where the action is triggered by clicking a graphic, all is well.

2
  • Have you checked the error console of Safari, Firefox or Chrome? Is there any error message? Commented Aug 18, 2011 at 11:51
  • 1
    Not an answer to your question, but your function could be rewritten as: function confirmRequest(questionText) { return confirm(questionText); } Commented Aug 18, 2011 at 12:21

1 Answer 1

1

Since you are using onclick, return true; in your confirmRequest function is simply allowing the rest of the clickHandler chain to be executed. I think you also need to explicitly submit the form at this time, in the true case.

Here is one way to do that, using only javascript:

function confirmRequest(questionText) {
  var confirmRequest = confirm(questionText);   
  if (confirmRequest) {
     document.forms[0].submit();
     return true;
  }
  else {
      return false;
  }
}
Sign up to request clarification or add additional context in comments.

4 Comments

onsubmit fails in both FF and IE.
See revised, you can continue to use onclick, but need to explicitly submit
I've adjusted it slightly to allow it to work to a form passed as a parameter. But it seems to work. Many thanks.
Yes, that would be more flexible. No problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.