473,385 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I make this form work with drop down list?

I made this code a while ago and had all text input. Now I am coming back through and adding drop downs to redundant values. The problem is when I add the selection list the wireSize function no longer sends the size to the inputbox on the html. I can't figure out the problem.

Here is the JS

Expand|Select|Wrap|Line Numbers
  1. function wireSize(){
  2.  
  3. var amps =(document.getElementById("resultbox4").value);
  4. var wire = document.wireNum.wire.value;
  5.  
  6. if (amps <= 20) && (wire == 3) {
  7. size = "3-#12 + #12grd in 3/4\" C";
  8. var result = document.getElementById("wireSize");
  9. result.value = size;
  10. }
  11. else
  12. if (amps <= 20) && (wire == 4) {
  13. size = "4-#10 + #10grd in 3/4\" C";
  14. var result = document.getElementById("wireSize");
  15. result.value = size;
  16. }
  17. else
  18. if (amps > 20 && amps <= 30) && (wire == 3) {
  19. size = "3-#10 + #10grd in 3/4\" C";
  20. var result = document.getElementById("wireSize");
  21. result.value = size;
  22. }
  23. else
  24. if (amps > 20 && amps <= 30) && (wire == 4) {
  25. size = "4-#10 + #10grd in 3/4\" C";
  26. var result = document.getElementById("wireSize");
  27. result.value = size;
  28. }}
And the html:

Expand|Select|Wrap|Line Numbers
  1. <h2>Wire size and 80%</h2>
  2.         <form name = "wireNum">
  3.         <input type="text" name="myresultbox" id="resultbox4" style="width:50px; height:16.775px;"> Amps<br>     
  4.         <select name="wire"> 
  5.         <option value=3>3W</option>
  6.         <option value=4>4W</option>  
  7.         </select><br>    
  8.         <input value="Click for 80%" onclick="percentAmps()" type="button"> 
  9.         <input type="text" name="myresultbox" id="ampPerc" style="width:50px; height:16.775px;"> Amps<br>
  10.         <input value="Click for Wire Size" onclick="wireSize()" type="button"> 
  11.         <input type="text" name="myresultbox" id="wireSize" style="width:200px; height:16.775px;"> <br>
  12.         <form>    
Any help is appreciated
Oct 5 '10 #1
6 1081
JKing
1,206 Expert 1GB
For the value of a select you need to access it's options array.

Expand|Select|Wrap|Line Numbers
  1. var wire = document.wireNum.wire.options[document.wireNum.wire.selectedIndex].value;
  2.  
That should fix it.
Oct 5 '10 #2
Does anything else need to be different because if I take the form and the drop list away the size gets inputted in the result box again. What is confusing is the percentAmps is working either way. But when I add the form the wireSize stops.
Oct 5 '10 #3
JKing
1,206 Expert 1GB
Can't comment on the percentAmps function without seeing the code for it.

Here I made a few minor changes to your javascript and html.

javascript: I added an extra set of brackets around all your if statements.
Expand|Select|Wrap|Line Numbers
  1. function wireSize(){
  2.  
  3. var amps =(document.getElementById("resultbox4").value);
  4. var wire = document.wireNum.wire.options[document.wireNum.wire.selectedIndex].value;
  5.  
  6. if ((amps <= 20) && (wire == 3)) {
  7. size = "3-#12 + #12grd in 3/4\" C";
  8. var result = document.getElementById("wireSizeText");
  9. result.value = size;
  10. }
  11. else
  12. if ((amps <= 20) && (wire == 4)) {
  13. size = "4-#10 + #10grd in 3/4\" C";
  14. var result = document.getElementById("wireSizeText");
  15. result.value = size;
  16. }
  17. else
  18. if ((amps > 20 && amps <= 30) && (wire == 3)) {
  19. size = "3-#10 + #10grd in 3/4\" C";
  20. var result = document.getElementById("wireSizeText");
  21. result.value = size;
  22. }
  23. else
  24. if ((amps > 20 && amps <= 30) && (wire == 4)) {
  25. size = "4-#10 + #10grd in 3/4\" C";
  26. var result = document.getElementById("wireSizeText");
  27. result.value = size;
  28. }}
  29.  
HTML: I added quotes around your option values and changed the id of "wireSize" to "wireSizeText" which was causing a conflict with your function name.
Expand|Select|Wrap|Line Numbers
  1. <h2>Wire size and 80%</h2>
  2.         <form name = "wireNum">
  3.             <input type="text" name="myresultbox" id="resultbox4" style="width:50px; height:16.775px;"> Amps<br>     
  4.             <select name="wire"> 
  5.                 <option value="3">3W</option>
  6.                 <option value="4">4W</option>  
  7.             </select><br>    
  8.             <input value="Click for 80%" onclick="percentAmps()" type="button"> 
  9.             <input type="text" name="myresultbox" id="ampPerc" style="width:50px; height:16.775px;"> Amps<br>
  10.             <input value="Click for Wire Size" onclick="wireSize()" type="button"> 
  11.             <input type="text" name="myresultbox" id="wireSizeText" style="width:200px; height:16.775px;"> <br>
  12.         </form>
  13.  
Oct 5 '10 #4
It seems as soon as I add the var to the js is breaks it. I can have the whole thing working with the select list in the html but the var wire breaks it. It's like the function won't take another variable.
Oct 5 '10 #5
JKing
1,206 Expert 1GB
Did you try the code I provided? I tested it and it works fine...

Could you post your current code?
Oct 5 '10 #6
It seems that changing the result box ID to wireSizeText was doing it. I am confused because it was always set up that way but when I added the var wire it would not work. I wonder why that is?
Thanks for your help.
Oct 5 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Dec | last post by:
Ok to simplify things I'll just give an example. This is pretty much what I want to do (minus the postcode): http://www.perrys.co.uk/usedcar?ID=F5J9BNNBMVK00DF I have relatively little...
2
by: kmnotes04 | last post by:
Is it possible to link one drop-down box to another? For example, if a name is chosen from a drop-down list, can another drop-down list then automatically display the person's office as a result of...
3
by: Stephen Adam | last post by:
Hi there, I'm sure i'm missing something really simple here, all i want to do is get the value of the selected item in a list box. Even after much fiddling about last night I still could not get...
2
by: Eric Dan | last post by:
Hi, Even tough I was able to implement what I want in a weird and non efficient way, I would like to get an opinion what is the right way to achieve my task: Scenario: • Display a DataGrid...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
2
by: Dave A | last post by:
I am stuggling with databinding a drop down list, hooking into the SelectedIndexChanged and attempting to avoid using the viewstate. The drop down list is quite large so I would prefer to avoid...
6
by: mcgrew.michael | last post by:
I hope this is the right group. I am very new to ASP so this is probably a stupid question. I have some vbscript that query's AD and populates a recordset. I know the recorset contains the...
5
by: nuevaenvb | last post by:
Hi all, I was wondering if someone could help me solve this problem, I have created a form which is supposed to do a simple update, these are my fields ProductId.text ...
1
by: student2008 | last post by:
Sorry about the title its a tricky one. I have a form which allows me to add a question and answers into a mysql database via a combination of, if a certain option is chosen and the reset button...
6
by: Palehorse | last post by:
I'd like to apologize upfront for me saying "I'm not a programer", I'm sure you all hear this a hundred times a day. Unfortunately, in this case, it's true. I've been working on trying to figure out...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.