Greaser9780 Posted March 1, 2007 Share Posted March 1, 2007 I want to use java to hide dropdown boxes untill a radio button is chosen. Then depending on which radio button is selected it shows the appropriate query in a dropdown. I don't use alot of java. I placed the function in the head of my document. And used onclick for the radio buttons to display the next dropdown. Everytime I click on one of the buttons at the bottom of my browser it shows an error is on the page. Any clues? Quote Link to comment Share on other sites More sharing options...
fenway Posted March 1, 2007 Share Posted March 1, 2007 How about providing us with some clues... like some sample code? Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted March 1, 2007 Author Share Posted March 1, 2007 OK I got the function and the code to work. Kind of. The user clicks on a radio button(position) to select which will inturn show the dropdown box with all the listed players at that position. The problem now is it works great for display but since all the other dropdowns are merely 'hidden' they still have values. When sending the form it always defaults to the last dropbox no matter which radio button is clicked on. Here is my code: <html><head><title>The Form</title> <script type="text/javascript"> function toggleField(field,vis) { if (vis) { document.getElementById(field).style.visibility = 'visible'; } else { document.getElementById(field).style.visibility = 'hidden'; } } </script> </head> <body> <form action="select.php" method="post"> <input type="radio" name="show" value="showone" onclick="toggleField('showone',true);toggleField('showtwo',false);toggleField('showthree',false) ;toggleField('showfour',false);toggleField('showfive',false);toggleField('showsix',false)" />QB<br /> <input type="radio" name="show" value="showtwo" onclick="toggleField('showone',false);toggleField('showtwo',true);toggleField('showthree',false) ;toggleField('showfour',false);toggleField('showfive',false);toggleField('showsix',false)" />WR<br /> <input type="radio" name="show" value="showthree" onclick="toggleField('showone',false);toggleField('showtwo',false);toggleField('showthree',true) ;toggleField('showfour',false);toggleField('showfive',false);toggleField('showsix',false) " />RB<br /> <input type="radio" name="show" value="showfour" onclick="toggleField('showone',false);toggleField('showtwo',false);toggleField('showthree',false);toggleField('showfour',true) ;toggleField('showfive',false);toggleField('showsix',false) " />TE<br /> <input type="radio" name="show" value="showfive" onclick="toggleField('showone',false);toggleField('showtwo',false);toggleField('showthree',false);toggleField('showfour',false);toggleField('showfive',true);toggleField('showsix',false)" />PK<br /> <input type="radio" name="show" value="showsix" onclick="toggleField('showone',false);toggleField('showtwo',false);toggleField('showthree',false);toggleField('showfour',false);toggleField('showfive',false);toggleField('showsix',true)" />DF<br /> <input type="radio" name="show" value="noshow" checked="checked" onclick="toggleField('showone',false);toggleField('showtwo',false);toggleField('showthree',false);toggleField('showfour',false);toggleField('showfive',false) ;toggleField('showsix',false) " />No Show <div name="showone" id="showone" style="visibility:hidden"> <select name='playername'> <?php include("db.php"); $sql4=mysql_query("SELECT * FROM players WHERE position='QB' and taken='0' ORDER BY name ASC") or die(mysql_error()); $res=mysql_fetch_array($sql4); $rst=$res['name']; $lab=$res['position']; while ($res = mysql_fetch_array($sql4, MYSQL_ASSOC)){ echo "<option value='" . $res['name'] . "'>" . $res['name'] . "</option>"; } ?> </select> </div> <div name="showtwo" id="showtwo" style="visibility:hidden"> <select name='playername'> <?php include("db.php"); $sql4=mysql_query("SELECT * FROM players WHERE position='WR' and taken='0' ORDER BY name ASC") or die(mysql_error()); $res=mysql_fetch_array($sql4); $rst=$res['name']; $lab=$res['position']; while ($res = mysql_fetch_array($sql4, MYSQL_ASSOC)){ echo "<option value='" . $res['name'] . "'>" . $res['name'] . "</option>"; } ?> </select> </div> <div name="showthree" id="showthree" style="visibility:hidden"> <select name='playername'> <?php include("db.php"); $sql4=mysql_query("SELECT * FROM players WHERE position='RB' and taken='0' ORDER BY name ASC") or die(mysql_error()); $res=mysql_fetch_array($sql4); $rst=$res['name']; $lab=$res['position']; while ($res = mysql_fetch_array($sql4, MYSQL_ASSOC)){ echo "<option value='" . $res['name'] . "'>" . $res['name'] . "</option>"; } ?> </select> </div> <div name="showfour" id="showfour" style="visibility:hidden"> <select name='playername'> <?php include("db.php"); $sql4=mysql_query("SELECT * FROM players WHERE position='TE' and taken='0' ORDER BY name ASC") or die(mysql_error()); $res=mysql_fetch_array($sql4); $rst=$res['name']; $lab=$res['position']; while ($res = mysql_fetch_array($sql4, MYSQL_ASSOC)){ echo "<option value='" . $res['name'] . "'>" . $res['name'] . "</option>"; } ?> </select> </div> <div name="showfive" id="showfive" style="visibility:hidden"> <select name='playername'> <?php include("db.php"); $sql4=mysql_query("SELECT * FROM players WHERE position='K' and taken='0' ORDER BY name ASC") or die(mysql_error()); $res=mysql_fetch_array($sql4); $rst=$res['name']; $lab=$res['position']; while ($res = mysql_fetch_array($sql4, MYSQL_ASSOC)){ echo "<option value='" . $res['name'] . "'>" . $res['name'] . "</option>"; } ?> </select> </div> <div name="showsix" id="showsix" style="visibility:hidden"> <select name='playername'> <?php include("db.php"); $sql4=mysql_query("SELECT * FROM players WHERE position='DF' and taken='0' ORDER BY name ASC") or die(mysql_error()); $res=mysql_fetch_array($sql4); $rst=$res['name']; $lab=$res['position']; while ($res = mysql_fetch_array($sql4, MYSQL_ASSOC)){ echo "<option value='" . $res['name'] . "'>" . $res['name'] . "</option>"; } ?> </select> </div> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
ki Posted March 2, 2007 Share Posted March 2, 2007 Okay first off: if (vis) { document.getElementById(field).style.visibility = 'visible'; } else { document.getElementById(field).style.visibility = 'hidden'; } } if (vis) ?????? it would be if (vis == "true") Quote Link to comment Share on other sites More sharing options...
fenway Posted March 2, 2007 Share Posted March 2, 2007 Okay first off: if (vis) { document.getElementById(field).style.visibility = 'visible'; } else { document.getElementById(field).style.visibility = 'hidden'; } } if (vis) ?????? it would be if (vis == "true") No, not really... Quote Link to comment Share on other sites More sharing options...
ki Posted March 2, 2007 Share Posted March 2, 2007 yea i just realized at what i said, now i feel dumb lol but try display: none; Quote Link to comment Share on other sites More sharing options...
fenway Posted March 2, 2007 Share Posted March 2, 2007 Why not have a default blank value for each drop-down? Quote Link to comment Share on other sites More sharing options...
Greaser9780 Posted March 2, 2007 Author Share Posted March 2, 2007 Tried <option selected></option> and it still always uses the last dropdown mox and tries to input a blank value in my table. I think the problem with this setup is all the dropdown still exist they are just hidden. Eventhough they are hidden they still hold data. That's why I went with the other script I posted under. Quote Link to comment Share on other sites More sharing options...
fenway Posted March 4, 2007 Share Posted March 4, 2007 I still say you need a default value that you can ignore on the server-side. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.