JavaScript: Return owner method from inside onclick function -


I am currently writing a custom dialogue box in JavaScript (to show dialog boxes with buttons, headings, etc.) )) Thus the message box of C #. Copying the show () method. However, I'm having trouble returning the value correctly from the function.

For example, the method I have to show () is static, and it is called with a button click:

    

Once MethodBox.Show () If the function is called, the dialog is displayed. I would like the option so that when the user clicks on the "yes" button, the MessageBox.Show () function returns right, otherwise it gets wrong. (Dynamic) button I have the code for:

  var button button = document createElement ('input'); YesButton.setAttribute ('type', 'button'); Yes buttons. Settabet ('value', 'yes'); Yes buttons. Settet ('name', 'button-yes'); Yes button Onclic = function () {message box.heid (); Back true; }; Var noButton = document.createElement ('Input'); NoButton.setAttribute ('type', 'button'); NoButton.setAttribute ('value', 'no'); NoButton.setAttribute ('name', 'button-no'); NoButton.onclick = function () {MessageBox.Hide (); return false; };  

However, as you can appreciate, the 'return false' / 'return true' statement indicates the button itself, and not the function (messbox shows.) What I would like to know, if there is any way, I can return the function when the user clicks (and only then) that the button is clicked on a button, so that the button is used correctly to call the function To be.

I find it difficult to understand what I am trying to achieve, but should understand the above version.

Thanks, Ben.

The way you are doing this, you can not refund any price, because the communication The function is finished soon after the box is created. I agree that if you press the button to cancel the default action ... then do this.

If the button is the the Button in the answer.

>
  thebutton.addEventListener ('click', function (e) {e.preventDefault (); // no one will submit / if the button is inside a form element then click MessageBox.Show (Message, message, 'Really delete', 'confirmation', false, this); // Here I send a button reference to be able to fire the event ______. To add an extra parameter ...} 1);  

Then within the MessageBox.Show () method, you assume that the This keyword was passed as a buttonrof .-

var Yebton = document. CreateElement ('Input'); YesButton.setAttribute ('type', 'button'); Yes buttons. Settabet ('value', 'yes'); Yes buttons. Settet ('name', 'button-yes'); Yes button Onclic = function () {message box.heid (); ButonRef.click (); }; Var noButton = document.createElement ('Input'); NoButton.setAttribute ('type', 'button'); NoButton.setAttribute ('value', 'no'); NoButton.setAttribute ('name', 'button-no'); NoButton.onclick = function () {MessageBox.Hide (); };

Then, if Yes is pressed, then input element will set a submitted event as if it was pressed.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -