Jump to content

Radio Button Selection ID


MGLP

Recommended Posts

I display a variable number of records and each one has a Radio button for the user to select.
Each record has a unique serial number.
How can I determine which record was selected and pass this on to my next php file.
e.g. of my code:
While($cntr < $NumRcds)
       {
        $cntr=$cntr+1;
        if ($AffectedRows > 0)
                 {
                   ($Row = mysql_fetch_row($Results));
                    print("<input type=\"radio\" name=\"rcd\" id=\"rcd\" value=\"$Row[6]\">);
                    $AffectedRows=$AffectedRows-1;
                }
       }
Thank you
Link to comment
Share on other sites

I am using the POST method and it doesn't work.  The $_POST['rcd'] does not contain anything.  It only works if I do a separate print for each record (instead of a loop routine as in my above code) and if I give each  <input> tag a separate name/id, e.g., rcdA, rcdB, rcdC, etc.  But I dont't want to do this - that's not the way to programme and I also don't know how many records - it's avariable number everytime.

So the question is how do I get to pass the "rcd" when using the loop method.

Link to comment
Share on other sites

OK.  I had  to make the "name"  different from the "id" in the <input> tag.

<input type=\"radio\" name=\"rcd\" id=\"rcd\" value=\"$Row[6]\">     DOES NOT WORK

<input type=\"radio\" name=\"choice\" id=\"rcd\" value=\"$Row[6]\">    WORKS

Thanks for your help! 

Link to comment
Share on other sites

It should work, just because it is not working at this moment doesn't mean this method is wrong! It just means that there is some mistake that is preventing it from working.

You can only select 1 single radio button at a time, so we know 'rcd' is not the problem, (Note the id ref will be wrong! As it will produce multiple duplicate id references, when they can only be unique within a page).

You can do a simple test to produce 3 radio non dynamically with plain html and see if the php page will pick up the selected value. If it work you have to produce the same result as the manual entered html.

<form method="post" action="somephppage.php">
  <input type="radio" name="rcd" id="rcd0" value="111111">
  <input type="radio" name="rcd" id="rcd1" value="222222">
  <input type="radio" name="rcd" id="rcd2" value="333333">
  
  <input type="submit" name="rcdsubmit" value="Submit to PHP page In action">
</form>

somephppage.php

echo $_POST['rcd'];

 

Edited by dsonesuk
Link to comment
Share on other sites

Unless you using JavaScript dot notation in some way to submit the form, it should make no difference

  <input type="radio" name="rcd" id="rcd" value="111111">
  <input type="radio" name="rcd" id="rcd1" value="222222">
  <input type="radio" name="rcd" id="rcd2" value="333333">

Will work just as well

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...