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

passing select input form values IE vs Firefox

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 2333
acoder
16,027 Expert Mod 8TB
Welcome to the site!

Do you get any errors? Can you show the HTML for the select element?
Apr 4 '08 #2
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 Expert Mod 8TB
Not tested, but adding values to the options should solve the problem:
[html]<option value="AK">AK[/html]
Apr 5 '08 #4
Seems to work, thank you very much!!!
Apr 5 '08 #5
acoder
16,027 Expert Mod 8TB
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
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:...
3
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....
12
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
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...
1
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"...
4
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...
21
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...
1
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...
1
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
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.