Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding two drop down list to get value for input field 1

Status
Not open for further replies.

vttech

Technical User
Joined
Jan 28, 2006
Messages
297
Location
US

I have a form that contains two <select> drop down list that contain numbers 0-10
and and <Input type=text> field that I want to contain the value of the addition of what is in <select name=num1> and select
<select name=num2>

Example:

one drop down list contains 2
the other drop down list contains 3
2 + 3 = 5

so 5 would appear in the input box as a value


any ideas how to accomplish this in javascript





Code:
<script language="javascript">

numberindex=1


document.write("<FORM NAME=\"Totals\">")

document.write("<SELECT name=\"num1\">")
for (var number=0; number<=10; number++)
     {
     alert(number)
     document.write("<OPTION value="+number+numberindex+">"+number+"</option>")
     }
document.write("</SELECT>")

document.write("<SELECT name=\"num2\">")
for (var number=0; number<=10; number++)
     {
     alert(number)
     document.write("<OPTION value="+number+numberindex+">"+number+"</option>")
     }
document.write("</SELECT>")


document.write("<INPUT TYPE=\"text\" NAME=\"Total\" value=\" \">")

document.write("</FORM>")

</script>

Newbie in search of knowledge
 
Code:
<script type="text/javascript">
<!--//
function calcTotal() {
    var d = document.this_form;
    var one = d.list_one.value;
    var two = d.list_one.value;
    d.total.value = (one + two);
}
//-->
</script>

<form name="this_form">

<select name="list_one" onChange="calcTotal()">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
</select>

<br>

<select name="list_two" onChange="calcTotal()">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
</select>

<br>

<input type="text" name="total">
</form>

M. Brooks
 
calculate the difference between two times

Thanks,

I am able to convert strings to numbers using parseInt() function.
Is there a function that does converts string to time?

If not

How do I Calculate the difference between two times that are strings


example

var StartTime = "7:00 AM"
var EndTIme = "9:00 PM"

Var CalTime = EndTIme - StartTime;











Newbie in search of knowledge
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top