user6234613 user6234613 - 7 months ago 13
HTML Question

Is it possible to retrieve the value from textbox before submission?

I have a

textbox
where users will input their mobile numbers.

<input type="number" name="mobileNumber" id="mobileNumber" runat="server" />


I also have a
dialog box
where I used it as a confirmation when the users click on the
submit
button.

var answer = confirm("The number you have entered is <%= confirmNumber %>.\nPlease verify if the number you have entered is correct.")

if (!answer) {
return false;
}


My expected output is here where __________ is supposed to be the
value
of the
textbox
.

(Apparently I don't have enough points to embed pictures yet?)

What I want to do is to retrieve the
value
from the
textbox
and replace the underscores in the
dialog box
with it.

Here is my C# attempt to retrieve the
value
from the
textbox
:

string confirmNumber = mobileNumber.Value;


I think that the C# code can only retrieve the
value
after the user has submitted? I am not really sure. Please help.

Answer

You want to show value that is entered on client side in textbox you can use javascript which you already have to show value to user. You have to use the ClientID of input to get its html element in javascript.

number = document.getElementById("<%=mobileNumber.ClientID%>").value;
var answer = confirm("The number you have entered is" + number  + ".\nPlease verify if the number you have entered is correct.")