Jump to content

Radio buttons to display query in a dropdown


Greaser9780

Recommended Posts

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?

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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")

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.