473,396 Members | 2,158 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,396 software developers and data experts.

I need help with the results of a select object

110 100+
I have a form with several questions whose answers are chosen from select object. Some work and some don't. Here's an example

This works:
Expand|Select|Wrap|Line Numbers
  1.     var y = document.getElementById('coverageDesired'); 
  2.     var z = y.options[y.selectedIndex].value; 
  3. if(z=="Property ONLY"){
  4.     document.getElementById('cellOutput05').innerHTML="Property coverage only";
  5.     } else if(z=="Liability ONLY"){
  6.     document.getElementById('cellOutput05').innerHTML="Liability coverage only";
  7.     } else if(z=="Property and Liability"){
  8.     document.getElementById('cellOutput05').innerHTML="Both Property and Liability coverage";
  9.     }
  10.  
This doesn't work:
Expand|Select|Wrap|Line Numbers
  1.     var y = document.getElementById('bankruptcy'); 
  2.             var z = y.options[y.selectedIndex].value;
  3.     if(z=="YES"){
  4.     status="REFERRED";
  5.     document.getElementById('cellOutput04').innerHTML="Risk has had a previous bankruptcy";
  6.     } else if(z=="NO"){
  7.     document.getElementById('cellOutput04').innerHTML="Risk has never filed bankruptcy";
  8.     }    
  9.  
Can anyone show me why the second one does not write the text to the screen like the first one does?
Dec 23 '08 #1
8 1085
acoder
16,027 Expert Mod 8TB
Can you show the corresponding HTML code for these elements?

Also, when you say it doesn't work, can you elaborate? Do you get any errors?
Dec 23 '08 #2
andersond
110 100+
Here's the HTML for the drop down box that works:
Expand|Select|Wrap|Line Numbers
  1. <table border="0" width="100%" id="tableQuestion5" onChange="javascript:question('5')" cellpadding="0" style="visibility:hidden">
  2.                 <tr>
  3.                   <td bgcolor="#003300" style="padding-right: 5px" width="55%">
  4.                   <p align="right">
  5.                   <font color="#FFFFFF" size="2" face="Arial Narrow"><b>
  6.                   Coverage(s) 
  7.                   desired:</b></font></td>
  8.                   <td width="45%" style="border: 1px solid #003300; padding-left: 3px; padding-top: 3px; padding-bottom: 3px">
  9.                   <select size="1" name="coverageDesired" id="coverageDesired" onChange="javascript:question('5')" style="font-family: Arial Narrow; font-size: 10pt; color: #000080; border: 1px solid #003300">
  10.                   <option>Select Coverages</option>
  11.                   <option value="Property ONLY">Property ONLY</option>
  12.                   <option value="Liability ONLY">Liability ONLY</option>
  13.                   <option value="Property and Liability">Property and Liability
  14.                   </option>
  15.                   </select></td>
  16.                 </tr>
  17.               </table>
  18.  
And here's the HTML for the drop down that doesn't work:
Expand|Select|Wrap|Line Numbers
  1. <table border="0" width="740" id="tableQuestion4" style="visibility:hidden" cellpadding="0">
  2.               <tr>
  3.                   <td bgcolor="#003300" style="padding-right: 5px" width="55%">
  4.                   <p align="right"><b>
  5.                   <font color="#FFFFFF" face="Arial Narrow" size="2">Has the 
  6.                   risk ever filed bankruptcy?</font></b></td>
  7.                   <td width="45%" style="border: 1px solid #003300; padding-left: 3px; padding-top: 3px; padding-bottom: 3px">
  8.                   <select size="1" name="bankruptcy" id="bankruptcy" onChange="javascript:question('4')" style="font-family: Arial Narrow; font-size: 10pt; color: #000080">
  9.                   <option>Select</option>
  10.                   <option value="NO             ">NO</option>
  11.                   <option value="YES           ">YES</option>
  12.                   </select></td>
  13.                 </tr>
  14.             </table>
  15.  
By "works" and "doesn't work" I mean that it does or does not display the message that corresponds to the user's choice. There are no error messages.
Dec 23 '08 #3
acoder
16,027 Expert Mod 8TB
In the onchange, you don't need the "javascript:" protocol.

Can you also post the cellOutput4 HTML code.

PS. use [code] tags rather than <code> tags.
Dec 23 '08 #4
phvfl
173 Expert 100+
There are trailing spaces on the options that do not work:
Expand|Select|Wrap|Line Numbers
  1. alert("no"=="no"); /* true */
  2. alert("no" == "no   "); /* false */
Dec 24 '08 #5
acoder
16,027 Expert Mod 8TB
That's correct. Strange I didn't notice that earlier.
Dec 24 '08 #6
xNephilimx
213 Expert 100+
please, don't use the onchange attribute of the select, unobtrusive javascript is alwasy for the best

Expand|Select|Wrap|Line Numbers
  1. var bankruptcy = document.getElemebtById('bankruptcy');
  2. bankruptcy.onchange = function() {
  3.    //use the this keyword to refer to bankruptcy select
  4. }
  5.  
Anyways i think the best solution is to use jquery, it really simplifies your code making it cleaner and shorter.

Expand|Select|Wrap|Line Numbers
  1. $('#bankruptcy').change(function(e) {
  2.    //use the this keyword ( or $(this) if you want extended functionality ) to refer to bankruptcy select
  3. });
  4.  
Dec 24 '08 #7
andersond
110 100+
Here's the cell output code

Expand|Select|Wrap|Line Numbers
  1. <tr>
  2.                   <td height="10" id="cellOutput01" width="50%"></td>
  3.                   <td height="10" id="cellOutput06" width="50%" colspan="1"></td>
  4.                 </tr>
  5.  
  6.                 <tr>
  7.                   <td height="10" id="cellOutput02" width="50%"></td>
  8.                   <td height="10" id="cellOutput07" width="50%" colspan="1"> </td>
  9.                 </tr>
  10.                 <tr>
  11.                   <td height="10" id="cellOutput03" width="50%"></td>
  12.                   <td height="10" id="cellOutput08" width="50%" colspan="1"></td>
  13.                 </tr>
  14.                 <tr>
  15.                   <td height="10" id="cellOutput04" width="50%"></td>
  16.                   <td height="10" id="cellOutput09" width="50%" colspan="1"></td>
  17.                 </tr>
  18.                 <tr>
  19.                   <td height="10" id="cellOutput05" width="50%"></td>
  20.                   <td height="10" id="cellOutput10" width="50%" colspan="1"></td>
  21.  
the trailing blanks that appear in the posted code do not exist in the actual code.
Dec 24 '08 #8
andersond
110 100+
Apologies! I was looking in the wrong place for the trailing blanks. Once they were eliminated everything worked. Thanks to everyone for your help.
Dec 24 '08 #9

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

Similar topics

2
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
5
by: MFC | last post by:
Ok, after three C# books, (C# How to Program, Programming in the Key of C#, and C# Weekend Crash Course) and three weeks, I believe I have tried everything to make a certain form function...
1
by: Don | last post by:
I am new to Indexing Services, have been researching the MS Site as well as web articles on DevHood, etc. I have set up a seperate catalog ("KnowledgeBase") on Win XP with a number of files. I am...
1
by: Miguel Dias Moura | last post by:
Hello, I am working on an ASP.NET/VB web site with Microsoft SQL 2000 database. I have a page with a search form where keywords are submitted. Consider I write the the keywords 'asp' and...
7
by: Joe | last post by:
Hi, I’m new to asp.net. I want to create an asp.net page that allows user to edit the data. I have pasted my code below. I am able to display the data in a datagrid. At the bottom of the page...
1
by: Siva | last post by:
Hi, In my ASP.Net 2.0 app, I have a gridview whose data is being populated using an object data source which retrieves data from a data access layer. The Select method returns a static list of...
8
by: Patti | last post by:
I am new to SQL and have created a stored procedure for a .net web application. Unfortunately I had to use a cursor in the stored procedure, so it is taking several minutes to execute because it...
13
by: PinkBishop | last post by:
I am using VS 2005 with a formview control trying to insert a record to my access db. The data is submitted to the main table no problem, but I need to carry the catID to the bridge table...
9
by: pic078 via AccessMonster.com | last post by:
I need serious help - I have a frontend/backend Access database (2 MDE Files) that remains stuck in task manager after exiting the application - you can't reopen database after exiting as a result...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.