Hello, I just want to know if this code can be improved, i made it kinda messing around with pieces of scripts i found here and there because I'm just a beginner with Javascript.
Code:<HEAD> <script type="text/javascript" src="jquery-1.3.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#bloc").change(function() { if ($("#bloc").val() == 2) { $("#bdays, #bdays2, #brea, #brea2").show("fast"); } else { $("#bdays, #bdays2, #brea, #brea2").hide(); } }); if ($("#bloc").val() == 2) { $("#bdays, #bdays2, #brea, #brea2").show("fast"); } else { $("#bdays, #bdays2, #brea, #brea2").hide(); } }); </script> </HEAD> <BODY> <select id="bloc"> <option value="1">Normal</option> <option value="2">Blocked</option> </select> <table border="1"> <tr> <td>value 1</td> <td>value 2</td> </tr> <tr> <td> <div id="bdays"> Days: </div> </td> <td> <div id="bdays2"> <input type="text" id="VIN" value=""> </div> </td> </tr> <tr> <td> <div id="brea"> Reason: </div> </td> <td> <div id="brea2"> <input type="text" id="VIN" value=""> </div> </td> </tr> </table> </BODY>
So, basically what i want to do is, based on the value of the select, if "2" (blocked), to display the next 2 <tr's> with the lenght of the block and the reason. I know it's messy but it's the only way i found to do this with a table, other ways when enabling the 2 <tr> elements it made a mess with the table.
The bloc value is also read from a db, so it should check if 1 or 2 and act according to it's value on page load. And of course, when changed to hide it or show it.
Also i noticed on Firebug that when switching to 2, and showing the next 2 fields, it was adding a bunch of style lines at first, and then was ok, but i tested it on Google Chrome and it does a weird thing, the width of the table grows a lot for a second and then comes back to normal.
Any help would be much appreciated!
Thanks!.



Reply With Quote

Bookmarks