niza Posted April 8, 2006 Share Posted April 8, 2006 Here's my code:[code]echo "<table cellspacing='10' border='0' cellpadding='0' width='100%'>";echo "<tr><td width='20'></td><td>Ad Name</td></tr>";while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) {extract($row);echo "<tr><td>[b]<input name='vAd' type='radio' value='$adID'>[/b]</td><td>{$row['adName']}</td></tr>";} echo "<tr><td colspan='2' width='10'><table cellspacing='10' border='0' cellpadding='0' width='100%'><tr><td>[b]<a href='edit_add.php?id=$adID'>[/b]Edit</a></td></tr></table></td></tr></table>"; [/code]I would like to pass the value $adID from the radio buttons[code]<input name='vAd' type='radio' value='$adID'>[/code]to this link here: [code]<a href='edit_add.php?id=$adID'>Edit</a>[/code]But no matter what radio button I choose, when I click the Edit link, the ID doesn't change. Any sugestions? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/6898-passing-values-from-radio-buttons-to-a-hyperlink/ Share on other sites More sharing options...
wildteen88 Posted April 9, 2006 Share Posted April 9, 2006 I do not understand your question. Do you want the value of your checkbox to go to your link when selected? If so this is not possible with PHP. Quote Link to comment https://forums.phpfreaks.com/topic/6898-passing-values-from-radio-buttons-to-a-hyperlink/#findComment-25253 Share on other sites More sharing options...
Vorotaev Posted April 9, 2006 Share Posted April 9, 2006 [!--quoteo(post=362860:date=Apr 8 2006, 05:30 PM:name=niza)--][div class=\'quotetop\']QUOTE(niza @ Apr 8 2006, 05:30 PM) [snapback]362860[/snapback][/div][div class=\'quotemain\'][!--quotec--]I would like to pass the value $adID from the radio buttons[code]<input name='vAd' type='radio' value='$adID'>[/code]to this link here: [code]<a href='edit_add.php?id=$adID'>Edit</a>[/code]But no matter what radio button I choose, when I click the Edit link, the ID doesn't change. Any sugestions? Thanks.[/quote]Unfortunately, what wildteen88 said is correct. PHP parses the page before ever sending it, and has no way to change the ID thereafter. You should use Javascript instead:[code]<script type="text/javascript">function uplink() { document.getElementById('ulink').href = 'edit_add.php?' + document.getElementByName('vAd').value;}</script><input name='vAd' type='radio' value='$adID'>...<a id="ulink" href='edit_add.php?id=$adID'>Edit</a>[/code]In this example, you would add the ID of "ulink" to the link in question so Javascript can interact with it. Quote Link to comment https://forums.phpfreaks.com/topic/6898-passing-values-from-radio-buttons-to-a-hyperlink/#findComment-25258 Share on other sites More sharing options...
kenrbnsn Posted April 9, 2006 Share Posted April 9, 2006 Values of checkboxes or any form input are only passed to your PHP script when the form is submitted.In your code snippet I don't see a form start or end "<form></form>" or a submit button.Here's how I would write this. I've left out all of the table stuff since that is only formatting and really should be done with CSS...[code]<?php$tmp = array();$tmp[] = '<form method="POST" action="edit_add.php">';$tmp[] = 'Ad Name: ';while ($row = mysql_fetch_array($result,MYSQL_ASSOC)) '<input name="vAd" type="radio" value='" . $row['adID'] . '"> ' . $row['adName'] . '<br>';$tmp[] = '<input type="submit" name="submit" value="Edit">';$tmp[] = '</form>';echo implode("\n",$tmp);?>[/code]When you choose a button and click the "Edit" button, the value of $_POST['vAd'] in your script edit_add.php will contain value you selected.Ken Quote Link to comment https://forums.phpfreaks.com/topic/6898-passing-values-from-radio-buttons-to-a-hyperlink/#findComment-25259 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.