Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
my code to get values entered in textboxes on confirm box on onclientclick event of button is as follows:
XML
<script type="text/javascript">
 function Confirmcall() {
        var call = parseInt (document.getElementById("txtEmpId").value) + document.getElementById("txtEmpName").value + parseInt( document.getElementById("txtSalary").value) + document.getElementById("txtCity").value;
        return confirm(call);
    }
    </script>


but when i click cancel in confirm box error occurs thatt input string is not in correct format . why? Also i want values to apper in confirm box like empid=1,empname=abc,sal=15000,city=xyz.Thanks
Posted

1 solution

The error in your code might be because you adding an integer with string. Try following code:
JavaScript
<script type="text/javascript">
function Confirmcall() {
var empId = document.getElementById("txtEmpId").value;
var empName = document.getElementById("txtEmpName").value;
var empSalary = document.getElementById("txtSalary").value;
var empCity = document.getElementById("txtCity").value;
var msg = "Emp ID: " + empId + ",Emp Name: " + empName + ",Emp Salary: " + empSalary + ", Emp City: " + empCity; 
return confirm(msg);
}
</script>


BTW, you could have used "improve question" in your question that you posted early today regarding the same problem.
 
Share this answer
 
Comments
Rambo_Raja 12-Jun-13 5:54am    
thnx..great!
Zafar Sultan 12-Jun-13 5:58am    
You're welcome.
Rambo_Raja 12-Jun-13 6:02am    
but please can you tell me why you put , in the following statement ",Emp Name: " + EmpName.
Zafar Sultan 12-Jun-13 6:04am    
"Emp Name: " is a string and EmpName is the value of textbox that will be appended to the message. At runtime it will be shown as Emp Name: XYZ(based on the input)
Zafar Sultan 12-Jun-13 6:07am    
Sorry, I didn't pay attention. You asked about putting a comma. Because it will be included in the output for readability. It is not mandatory. You will get the output as Emp ID: 1, Emp Name: XYZ, Emp Salary: 40000, Emp City: Mumbai

(Based on the input provided)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900