Click here to Skip to main content
14,664,507 members
Rate this:
Please Sign up or sign in to vote.
See more:
my code to get values entered in textboxes on confirm box on onclientclick event of button is as follows:
<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

Rate this:
Please Sign up or sign in to vote.

Solution 1

The error in your code might be because you adding an integer with string. Try following code:
<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.
   
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)
Rambo_Raja 12-Jun-13 6:10am
   
okey..thank you for being such responsive..
Zafar Sultan 12-Jun-13 6:18am
   
Anytime dear.
Rambo_Raja 28-Jun-13 1:59am
   
Hi zafar ji ...i want to make following changes in the above question like i want a new window to open when user clicks on submit button not popup window. and in that new window names should comes like
1.Name:
2.DOB:
3.AGE:
4.ADD:
5.Phn:
5.Country:
6.State:
7.City:
along with are u sure? Ok button and cancel button on the very same page. seeking your help.

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100