473,386 Members | 1,706 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,386 software developers and data experts.

javascript works perfectly in IE and firefox but fails in Chrome and Safari

2
hi everyone, this is my 1st post here in this community forum, just would like to say "HI" to everyone.

i would like to share with you my experience in developing multiple dependency selection form developed in java script, how this script works is that when 1st selection is selected, based on the value the user select, a second level selection will appear and so on.

below is the Java-script code along with my form code too

javascript:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.  
  3. function nextSelect(o) {
  4.  
  5.     if (o.value == '0') {
  6.         var next = o.nextSibling;
  7.         while (next && next.nodeName != 'SELECT') {
  8.             next = next.nextSibling;
  9.         }
  10.         next.length = 0;
  11.  
  12.         return;
  13.     }
  14.     var d = document;
  15.  
  16.     var useSelect = d.getElementById(o.name + '_' + o.value);
  17.  
  18.     if (!useSelect) {
  19.         alert('Unknown id: ' + o.name + '_' + o.value);
  20.         return;
  21.     }
  22.  
  23.     var copy = useSelect.cloneNode(true);
  24.     copy.style.display = 'inline';
  25.  
  26.     var next = o.nextSibling;
  27.     while (next && next.nodeName != 'SELECT') {
  28.         next = next.nextSibling;
  29.     }
  30.     next.parentNode.insertBefore(copy, next);
  31.     next.parentNode.removeChild(next);
  32. }
  33. </script>
my form:
Expand|Select|Wrap|Line Numbers
  1. <div style="display: none;">
  2.  
  3. <!-- ##### First Selection ####### --> 
  4.  
  5. <select name="second" id="first_dp" onchange="nextSelect(this);">
  6. <option value="0">Choose</option>
  7. <option value="dp_2_38">2 3/8'</option>
  8. <option value="dp_4">4'</option>
  9. </select>
  10.  
  11. <select name="second" id="first_hw" onchange="nextSelect(this);">
  12. <option value="0">Choose</option>
  13. <option value="hw_3_12">3 1/2'</option>
  14. <option value="hw_4">4'</option>
  15. </select>
  16.  
  17. <!-- ####### 2nd Selection ####### --> 
  18.  
  19. <select name="third" id="second_dp_2_38" onchange="nextSelect(this);">
  20. <option value="0">Choose</option>
  21. <option value="dp_2_38_4.85">4.85 lbs/ft</option>
  22. <option value="dp_2_38_6.65">6.65 lbs/ft</option>
  23. </select>
  24. <select name="third" id="second_dp_2_78" onchange="nextSelect(this);">
  25. <option value="0">Choose</option>
  26. <option value="dp_2_78_6.85">6.85 lbs/ft</option>
  27. <option value="dp_2_78_10.4">10.4 lbs/ft</option>
  28. </select>
  29.  
  30. >>>>>>and so on till 3rd selection<<<<<<<<<
  31.  
  32. </div>
  33.  
  34. <form action="pdfHandle.php" method="post" id="pdfsearch">
  35. <fieldset>
  36.     <table border="0" cellpadding="0" cellspacing="0">
  37.       <tr>
  38.         <td width="142" height="146">
  39.                 <p>
  40.             Type:<br />
  41.             Size:<br />
  42.             Weight:<br />
  43.         </td>
  44.         <td width="266"><select name="first" onclick="nextSelect(this);">
  45.           <option value="0">Choose</option>
  46.           <option value="dp">Drill Pipe</option>
  47.           <option value="hw">Heavy Weight</option>
  48.           </select><br/>
  49.           <select name="select">
  50.           </select>
  51.           <br/>
  52.           <select name="select">
  53.           </select>
  54.           <br/>
  55.           <select name="select">
  56.           </select>
  57.  
  58.        </td>
  59.     </tr>
  60.   </table>
  61.     <p>
  62.       <input type="submit" name="submit" id="submit" value="Create PDF" />
  63.      <input type="reset" value="Reset Selection" /> 
  64.     </p>
  65. </fieldset>
  66. </form>
i would like to know what i am missing here and what is making Safari n chrome not to run this page properly, when u execute this code, only the 1st selection will appear while the rest of the selections are Null, i hope someone will guide me through this or direct me to solution or any other way of doing this perhaps

i thank you for viewing this post.
Apr 26 '10 #1
2 2763
@ozalkl
I don't know whether you have enabled java script or not. Because in my machine it is working fine in chrome. But one thing is weird that 1st time wen m selecting in 1st selection box the 2nd one remain unchanged i.e. without any entry. And 2nd time when i am selecting again in 1st selection box then only 2nd one is being activated.

Regards,
Rahul
Apr 27 '10 #2
ozalkl
2
hi Rahul, yes i have the jscript enabled in chrome, the concept of this form selection is as follow:

once you select the 1st selection option then only the 2nd level selection will appair with a depending option based on the 1st selection. that 2nd selection is set in the Div container, while the jscript is calling the right selection to match the above option which we selected earlier.

is there anything i need to change in my javascript coding or i need to add additional codes in order to make my script friendly with Chrome n Safari...
Apr 27 '10 #3

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

Similar topics

1
by: npm | last post by:
Hi I've checked out this page (and it works fine) in FF, IE, Opera, Chrome and Safari: http://www.w3schools.com/dom/tryit.asp?filename=try_dom_list_loop But when I try and tweak it for a site...
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:
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
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
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,...
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...

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.