473,624 Members | 2,119 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing select input form values IE vs Firefox

3 New Member
I have javascript code which passes select input form field values in Firefox and Opera but it does not seem to work in IE7.

This form runs a search, and the search results page has the same form at the top of the page with values filled in.

In Firefox the fields are passed correctly. In IE7 the select field "selected" option is not passed correctly, rather the drop-down select field reverts to the default/top field.

Here is the code:


Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.     var arrQs = location.search.substring(1).split("&");
  3.     for (x = 0; x < arrQs.length; x++) {
  4.         if (arrQs[x].split("=")[0] == 'in_state') {
  5.             var val = arrQs[x].split("=")[1];
  6.         }
  7.     }
  8.     if (val != null) {
  9.         var e = document.forms[0].elements;
  10.         for (x = 0; x < e.length; x++) {
  11.             if (e[x].name && e[x].name == 'in_state') {
  12.                 for (o = 0; o < e[x].options.length; o++)
  13.                     if (e[x][o].value == val)
  14.                     e[x][o].selected = true;
  15.             }
  16.         }
  17.     }
  18. </script>
  19.  
  20.  
Thanks, Mike.
Apr 4 '08 #1
5 2357
acoder
16,027 Recognized Expert Moderator MVP
Welcome to the site!

Do you get any errors? Can you show the HTML for the select element?
Apr 4 '08 #2
mwpclark
3 New Member
Thanks acoder!

The html code is actually formed by some perl scripts. Here is the way it appears on the page, sorry this may be a bit long. The screenshots show that Firefox displays the state abbreviation, while IE7 does not.

FIREFOX



Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3.   <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4.   <TITLE>Network Hunter White Pages</TITLE>
  5. <style>
  6. body{font-family:arial;font-size:12px;background-image:url(/multitude.gif);background-repeat:no-repeat;padding:0px;margin:0px;}
  7. td{font-family:arial;font-size:12px;padding:0px;margin:0px;}
  8. h1{font-size:16px;font-weight:bold;padding-left:0px;padding-top:5px;color:#666666;}
  9. .copy{font-size:11px;color=666666;text-align:center;}
  10. a, a:visited{color:000033;}
  11. </style> 
  12. <script language="javascript">
  13. function syncElement(sName, sType) {
  14.     var arrQs = location.search.substring(1).split("&");
  15.     for (x = 0; x < arrQs.length; x++) {
  16.         if (arrQs[x].split("=")[0] == sName) {
  17.             var val = arrQs[x].split("=")[1];
  18.         }
  19.     }
  20.     if (val != null) {
  21.         var e = document.forms[0].elements;
  22.         for (x = 0; x < e.length; x++) {
  23.             if (e[x].name && e[x].name == sName) {
  24.                 switch (sType.toLowerCase()) {
  25.                     case "radio":
  26.                     case "checkbox":
  27.                         if (e[x].value && e[x].value == val)
  28.                             e[x].checked = true;
  29.                         break;
  30.                     case "select":
  31.                         for (o = 0; o < e[x].options.length; o++)
  32.                             if (e[x][o].value == val)
  33.                                 e[x][o].selected = true;
  34.                         break;
  35.                     case "text":
  36.                         e[x].value = val;
  37.                         break;
  38.                 }
  39.             }
  40.         }
  41.     }
  42. }
  43. </script>
  44.  
  45. </HEAD>
  46. <body><img src=/clear.gif height=65 width=760 vspace=0 hspace=0 border=0><br><center>
  47. <table cellspacing=0 cellpadding=0><tr>
  48. <td valign=top><a href=/><img src=/candidates.gif border=0 title="Home"></a></td>
  49. <td valign=top align=center nowrap>
  50.  
  51. <img src=/network-hunter.gif alt="Network Hunter" title="Network Hunter" border=0 vspace=5 hspace=10>
  52. <h1>White Pages Search <br> Lookup U.S. and Canadian<br>Phone Numbers and Addresses.</h1>
  53. <a href="/cgi-bin/nph-x.cgi" style="font-weight:bold;color:#0000cc">Back to Candidate Search</a>
  54. </td><td>
  55. <script language="javascript">
  56. function escapeLocation() {
  57.     var e = document.forms[0].elements;
  58.     for (x = 0; x < e.length; x++) {
  59.         if (e[x].name && e[x].name == 'in_location' && e[x].value.search(' ') > -1) {
  60.             e[x].value = e[x].value.replace(/ /g,"-");
  61.         }
  62.     }
  63.     return true;
  64. }
  65. </script>
  66. <FORM ACTION="http://www.networkhunter.com/white-pages/nph-x.cgi" method=GET onsubmit="return escapeLocation();">
  67.  
  68.  
  69.  
  70. <INPUT TYPE=hidden name=category value="people">
  71. <input type=hidden name=per_page value=100>
  72.  
  73. <input type=hidden name=timeout value=60>
  74.  
  75. <font style="font-size:12px">
  76. last name (required)<br>
  77. <INPUT TYPE="text" NAME="qry_str" VALUE="jones" style="width:285px" id=lastname><br>
  78. first<br>
  79. <INPUT TYPE="text" NAME="in_firstname" VALUE="bob" style=width:285px id=firstname><br>
  80. location<br>
  81. <INPUT TYPE="text" NAME="in_location" VALUE='' style=width:285px><br>
  82. <table border=0 width=285><tr><td class=heading style="font-size:12px;" colspan=2>
  83. Select State / Province&nbsp;&nbsp;
  84. </td></tr><tr><td>
  85. <SELECT NAME = "in_state" size=1>
  86.  
  87. <option value="">USA
  88. <option>AK
  89. <option>AL
  90. <option>AR
  91. <option>AZ
  92. <option>CA
  93. <option>CO
  94. <option>CT
  95. <option>DC
  96. <option>DE
  97. <option>FL
  98. <option>GA
  99. <option>HI
  100. <option>IA
  101. <option>ID
  102. <option>IL
  103. <option>IN
  104.  
  105. <option>KS
  106. <option>KY
  107. <option>LA
  108. <option>MA
  109. <option>MD
  110. <option>ME
  111. <option>MI
  112. <option>MN
  113. <option>MO
  114. <option>MS
  115. <option>MT
  116. <option>NC
  117. <option>ND
  118. <option>NE
  119. <option>NH
  120. <option>NJ
  121. <option>NM
  122.  
  123. <option>NV
  124. <option>NY
  125. <option>OH
  126. <option>OK
  127. <option>OR
  128. <option>PA
  129. <option>RI
  130. <option>SC
  131. <option>SD
  132. <option>TN
  133. <option>TX
  134. <option>UT
  135. <option>VA
  136. <option>VT
  137. <option>WA
  138. <option>WI
  139. <option>WV
  140.  
  141. <option>WY
  142. <option>CANADA
  143. <option>AB
  144. <option>BC
  145. <option>MB
  146. <option>NB
  147. <option>NL
  148. <option>NT
  149. <option>NS
  150. <option>NU
  151. <option>ON
  152. <option>PE
  153. <option>QC
  154. <option>SK
  155. <option>YT
  156. </select><br>
  157. </td><td align=right valign=bottom>
  158.  
  159. <INPUT TYPE=image src=/search-white-pages.gif alt="Search White Pages!">
  160. </td></tr></table>
  161. <input type=hidden name=depth value=3>
  162.  
  163.  
  164.  
  165.  
  166. </td></tr></FORM></table>
  167. </td></tr></table>
  168. <script language="javascript">
  169.     var arrQs = location.search.substring(1).split("&");
  170.     for (x = 0; x < arrQs.length; x++) {
  171.         if (arrQs[x].split("=")[0] == 'in_state') {
  172.             var val = arrQs[x].split("=")[1];
  173.         }
  174.     }
  175.     if (val != null) {
  176.         var e = document.forms[0].elements;
  177.         for (x = 0; x < e.length; x++) {
  178.             if (e[x].name && e[x].name == 'in_state') {
  179.                 for (o = 0; o < e[x].options.length; o++)
  180.                     if (e[x][o].value == val)
  181.                     e[x][o].selected = true;
  182.             }
  183.         }
  184.     }
  185. </script>
  186. &nbsp;<CENTER><img src="/processing.gif" name="processing">
  187. </CENTER><SCRIPT language="javascript"><!--
  188. document.images['processing'].src = "/spacer.gif";
  189. //--> </SCRIPT><table border=0 cellspacing=0 cellpadding=2 style="background-color:#000000"><tr><td>
  190. <table border=0 cellspacing=0 cellpadding=10 bgcolor=white><tr><td>
  191.  
  192. <snip>
IE7



Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3.   <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4.   <TITLE>Network Hunter White Pages</TITLE>
  5. <style>
  6. body{font-family:arial;font-size:12px;background-image:url(/multitude.gif);background-repeat:no-repeat;padding:0px;margin:0px;}
  7. td{font-family:arial;font-size:12px;padding:0px;margin:0px;}
  8. h1{font-size:16px;font-weight:bold;padding-left:0px;padding-top:5px;color:#666666;}
  9. .copy{font-size:11px;color=666666;text-align:center;}
  10. a, a:visited{color:000033;}
  11. </style> 
  12. <script language="javascript">
  13. function syncElement(sName, sType) {
  14.     var arrQs = location.search.substring(1).split("&");
  15.     for (x = 0; x < arrQs.length; x++) {
  16.         if (arrQs[x].split("=")[0] == sName) {
  17.             var val = arrQs[x].split("=")[1];
  18.         }
  19.     }
  20.     if (val != null) {
  21.         var e = document.forms[0].elements;
  22.         for (x = 0; x < e.length; x++) {
  23.             if (e[x].name && e[x].name == sName) {
  24.                 switch (sType.toLowerCase()) {
  25.                     case "radio":
  26.                     case "checkbox":
  27.                         if (e[x].value && e[x].value == val)
  28.                             e[x].checked = true;
  29.                         break;
  30.                     case "select":
  31.                         for (o = 0; o < e[x].options.length; o++)
  32.                             if (e[x][o].value == val)
  33.                                 e[x][o].selected = true;
  34.                         break;
  35.                     case "text":
  36.                         e[x].value = val;
  37.                         break;
  38.                 }
  39.             }
  40.         }
  41.     }
  42. }
  43. </script>
  44.  
  45. </HEAD>
  46. <body><img src=/clear.gif height=65 width=760 vspace=0 hspace=0 border=0><br><center>
  47. <table cellspacing=0 cellpadding=0><tr>
  48. <td valign=top><a href=/><img src=/candidates.gif border=0 title="Home"></a></td>
  49. <td valign=top align=center nowrap>
  50. <img src=/network-hunter.gif alt="Network Hunter" title="Network Hunter" border=0 vspace=5 hspace=10>
  51. <h1>White Pages Search <br> Lookup U.S. and Canadian<br>Phone Numbers and Addresses.</h1>
  52. <a href="/cgi-bin/nph-x.cgi" style="font-weight:bold;color:#0000cc">Back to Candidate Search</a>
  53. </td><td>
  54. <script language="javascript">
  55. function escapeLocation() {
  56.     var e = document.forms[0].elements;
  57.     for (x = 0; x < e.length; x++) {
  58.         if (e[x].name && e[x].name == 'in_location' && e[x].value.search(' ') > -1) {
  59.             e[x].value = e[x].value.replace(/ /g,"-");
  60.         }
  61.     }
  62.     return true;
  63. }
  64. </script>
  65. <FORM ACTION="http://www.networkhunter.com/white-pages/nph-x.cgi" method=GET onsubmit="return escapeLocation();">
  66.  
  67.  
  68.  
  69. <INPUT TYPE=hidden name=category value="people">
  70. <input type=hidden name=per_page value=100>
  71. <input type=hidden name=timeout value=60>
  72.  
  73. <font style="font-size:12px">
  74. last name (required)<br>
  75. <INPUT TYPE="text" NAME="qry_str" VALUE="jones" style="width:285px" id=lastname><br>
  76. first<br>
  77. <INPUT TYPE="text" NAME="in_firstname" VALUE="bob" style=width:285px id=firstname><br>
  78. location<br>
  79. <INPUT TYPE="text" NAME="in_location" VALUE='' style=width:285px><br>
  80. <table border=0 width=285><tr><td class=heading style="font-size:12px;" colspan=2>
  81. Select State / Province&nbsp;&nbsp;
  82. </td></tr><tr><td>
  83. <SELECT NAME = "in_state" size=1>
  84. <option value="">USA
  85. <option>AK
  86. <option>AL
  87. <option>AR
  88. <option>AZ
  89. <option>CA
  90. <option>CO
  91. <option>CT
  92. <option>DC
  93. <option>DE
  94. <option>FL
  95. <option>GA
  96. <option>HI
  97. <option>IA
  98. <option>ID
  99. <option>IL
  100. <option>IN
  101. <option>KS
  102. <option>KY
  103. <option>LA
  104. <option>MA
  105. <option>MD
  106. <option>ME
  107. <option>MI
  108. <option>MN
  109. <option>MO
  110. <option>MS
  111. <option>MT
  112. <option>NC
  113. <option>ND
  114. <option>NE
  115. <option>NH
  116. <option>NJ
  117. <option>NM
  118. <option>NV
  119. <option>NY
  120. <option>OH
  121. <option>OK
  122. <option>OR
  123. <option>PA
  124. <option>RI
  125. <option>SC
  126. <option>SD
  127. <option>TN
  128. <option>TX
  129. <option>UT
  130. <option>VA
  131. <option>VT
  132. <option>WA
  133. <option>WI
  134. <option>WV
  135. <option>WY
  136. <option>CANADA
  137. <option>AB
  138. <option>BC
  139. <option>MB
  140. <option>NB
  141. <option>NL
  142. <option>NT
  143. <option>NS
  144. <option>NU
  145. <option>ON
  146. <option>PE
  147. <option>QC
  148. <option>SK
  149. <option>YT
  150. </select><br>
  151. </td><td align=right valign=bottom>
  152. <INPUT TYPE=image src=/search-white-pages.gif alt="Search White Pages!">
  153. </td></tr></table>
  154. <input type=hidden name=depth value=3>
  155.  
  156.  
  157.  
  158.  
  159. </td></tr></FORM></table>
  160. </td></tr></table>
  161. <script language="javascript">
  162.     var arrQs = location.search.substring(1).split("&");
  163.     for (x = 0; x < arrQs.length; x++) {
  164.         if (arrQs[x].split("=")[0] == 'in_state') {
  165.             var val = arrQs[x].split("=")[1];
  166.         }
  167.     }
  168.     if (val != null) {
  169.         var e = document.forms[0].elements;
  170.         for (x = 0; x < e.length; x++) {
  171.             if (e[x].name && e[x].name == 'in_state') {
  172.                 for (o = 0; o < e[x].options.length; o++)
  173.                     if (e[x][o].value == val)
  174.                     e[x][o].selected = true;
  175.             }
  176.         }
  177.     }
  178. </script>
  179. &nbsp;<CENTER><img src="/processing.gif" name="processing">
  180. </CENTER><SCRIPT language="javascript"><!--
  181. document.images['processing'].src = "/spacer.gif";
  182. //--> </SCRIPT><table border=0 cellspacing=0 cellpadding=2 style="background-color:#000000"><tr><td>
  183. <table border=0 cellspacing=0 cellpadding=10 bgcolor=white><tr><td>
  184. <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="760">
  185.   <TR VALIGN="Top">
  186.     <TD><SMALL>Total </SMALL><B>24</B> <SMALL> results<BR></FONT>
  187.       &nbsp;</TD>
  188.     <TD><P ALIGN=Right>
  189. <snip>
  190. &nbsp;&nbsp;</SMALL></I></TD>
  191.   </TR>
  192. </TABLE>
  193. <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="600">
  194.   <TR VALIGN="Top">
  195.     <TD style="font-size:12px;"><B>Page:&nbsp;1</B></FONT></TD>
  196.     <TD><P ALIGN=Right>
  197.       &nbsp;<I>&nbsp;</I></TD>
  198.   </TR>
  199.   <TR>
  200.     <TD COLSPAN=2>
  201.     <HR SIZE=1>
  202.     </TD>
  203.   </TR>
  204. </TABLE>
  205. <TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="600">
  206.   <TR>
  207.     <TD style="font-size:12px;"><B>
  208.       Results:
  209.       &nbsp;1
  210.       - 24</B></FONT>
  211.       <P>
  212.       <div style="background-color: #FAE8C8;font-size:12px;text-align:left;">
  213.  
  214. <snip>
  215.  
  216.  
Apr 4 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Not tested, but adding values to the options should solve the problem:
[html]<option value="AK">AK[/html]
Apr 5 '08 #4
mwpclark
3 New Member
Seems to work, thank you very much!!!
Apr 5 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
You're welcome. Glad you've got it working. Post back to the forum if you have any more questions.
Apr 6 '08 #6

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

Similar topics

1
7779
by: Paul | last post by:
Hmmm, didn't seem to work. I have set session.use_cookies = 1 and session.use_trans_sid = 1 in my php.ini file. Index.php contains: ---------------------------------------------------------------------------- <?php ini_set("session.use_cookies", "off"); ini_set("session.use_trans_sid", "on"); session_start(); $_SESSION = ""; $_SESSION = ""; echo "<form method='POST' action='login.php'>
3
4976
by: Fredrik/Sweden | last post by:
Hi folks ! got this problem... i have a table 'Accounts' in my database, which contains a bunch of users. From the main menu i choose "edit user" and all users in the db are presented in a table. The first column 'Pnr' is a unique ID for each user that i made appear as a link. clicking on one userID should present a form where the picked users userdata is already filled in so i can easily edit it and then move on to submit the form to...
12
8868
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
11
1516
by: ddailey | last post by:
I have a select named "s" in a form named "f": By default only one of the options in the select appears on the page -- that is how I want it. What I'd like to do is simulate a click on the select so that all of its options become visible -- i.e., its option box opens to reveal all document.f.s.options.length options. I've tried the following:
1
5009
by: Jan Doggen | last post by:
Hello all, I have a SELECT like this (the 'alert()s are temporary): <FORM method="POST" action="/scripts/runisa.dll?OVB2.132964:PGSPLITVACAFMELDEN:1095144287.9159" id="hulpform" name="hulpform"> <select name="varVervuld" id="varVervuld" onChange="alert('Onchange');Vervuld(this.options);"> <option value="0" selected="selected">&nbsp;</option> <option value=JA>Ja</option>
4
2707
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays multiple dynamic rows with chechboxs, input box for units of service, description of the service and each row has its own dropdown list of unit fees that apply.
21
29769
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays prodcut anme have used ajax to avoid refreshing of page this works fine 2.now i have created one row with checkbox|select box|text|text|text|text| where in the select box values are fetched from table here also i have used ajax for getting the m_name...
1
4859
by: CMani | last post by:
Hi, I have an select element which has hidden attribute for each of item. Say Employee Id are listed in List Box, the Name and gender are kept in value and ATTRIB respectively for each code in the list box . I want to display the Code, Name and gender of the selected Employee, so i wrote on change event for the select element and invoke the javascript to populate the values to the corresponding input text box. The Html Code is ...
1
2175
by: mbcode | last post by:
I am trying to use a Javascript picklist box and then echo the chosen values back to the screen (and insert in the db later) but I am getting the Button value rather than the list values. I have followed the advice on the forum to us and ID and getElementByID in the <select> line, but no luck. Thanks in advance HTML </head> <body> <form method="post" name="combo_box" action=subscribe3.php> <table cellpadding="4" cellspacing="0"...
0
8234
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8172
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.