tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
can you pls tell me what i have done wrong here?
i want to add input1 and input2 together and then display it in the msgbox,
the strange thing is that it works when i want to subtract multiply and divide but not add
<script type="text/javascript">
function valid(form)
{
var input1=0;
var input2=0;
var tot = 0;
input1 = document.myform.data1.value;
input2 = document.myform.data2.value;
tot = input1 + input2;
alert("Hello " + tot + "! Welcome...");
}
</SCRIPT>
Click on the button after entering your
name into the text box:<BR>
<form name="myform">
<input type="text" name="data1" value="" size=10>
<input type="text" name="data2" value="" size=10>
<INPUT TYPE="button" VALUE="Click Here" onClick="valid(this.form)">
</form>
<script type = 'text/javascript'>
var i = 3, j = 5, k;
var l = "str";
var m = "500";
k = i + j; //returns an i nteger; output should be 8
document.write(k + "<br />");
k = 3 + l; //returns a string since one of the operands is a string; output should be 3str
document.write(k + "<br />");
k = l + m;//returns string since both operands are strings; output should be str500
document.write(k + "<br />");
k = i + m; //returns 3500
document.write(k + "<br />");
k = i + parseInt(m); //returns 503
document.write(k + "<br />");
</script>