DanielHardy Posted January 17, 2011 Share Posted January 17, 2011 Hi all, I have written a fairly simple update script. Each new "topic" from the database is dragged up from the database and displayed with a radio button. The user then clicks a radio button (chooses a topic to edit), and they can then type new text into a textbox that will update that article when submitted. This is working fine, but what I want to do is place the "message" of the selected radio button in the textbox (so it can be directly edited) using an onclick event (yes I realise or this is javascript) or equivelent. I already have the data printing to the page so hopefully this will be an easy one for someone out there. Code below: <?php mysql_connect("", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); $updated = FALSE; if(count($_POST) > 0){ $admin = $_POST['admin']; array_map("intval",$admin); $admin = implode(",",$admin); $user = $_COOKIE['ID_my_site']; $message = $_POST['message']; if (isset($_POST['admin'])) { mysql_query("UPDATE messages SET message='$message' WHERE id = '$admin'") or trigger_error(mysql_error(),E_USER_ERROR); $edit = mysql_query("SELECT message FROM messages"); if($id=='1'){ echo ("$edit"); } echo "<script language=javascript>alert('Post updated!')</script>"; $updated=TRUE; header( 'Location: forum.php' ) ; } else { echo "<script language=javascript>alert('You did not select a post!')</script>"; } } ?> <form name="form22" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" style="margin-top:40px;"> <?php ?> <?php $booked = "<b>Seat Booked</b>"; $sql = "SELECT id,title,message FROM messages ORDER by id DESC"; $result = mysql_query($sql) or trigger_error(mysql_error(),E_USER_ERROR); while(list($id,$title,$message)=mysql_fetch_row($result)){ echo '<div style="border:5px dashed #ff0000;width:250px;text-align:center;float:left;margin-left:15px;margin-bottom:5px;padding-bottom:5px;"><b><font color="black"><h2>'.$title.'</h2></b><p> '.$message.'</p><input id="chk" type="radio" name="admin[]" onclick="javascript:document.form22.car.disabled=false" value="'.$id.'" /></font></div>'."\n"; } ?> Plus the textbox code should you need it: <textarea id="car" name="message" onkeyup="valsub()" disabled style="width:830px;"><? echo "cheese"; ?></textarea><p> <input id="btn" type="submit" name="submit" value="Edit Post" disabled /> You can see the working script at: http://danielrhyshardy.com/AWT/forumedit.php Thanks in advance guys Dan Quote Link to comment https://forums.phpfreaks.com/topic/224699-radio-box-to-display-database-data-in-textbox/ Share on other sites More sharing options...
brianlange Posted January 17, 2011 Share Posted January 17, 2011 I wouldn't put the text inside the id attribute. Here's an example using hidden divs. The value of the form element is passed to the javascript function and the text of the hidden div is accessed using document.getElementById. http://gonavygolf.com/test11.html Also, you can't put html inside of the textarea field. Notice how the <br> tags show up. -Brian Quote Link to comment https://forums.phpfreaks.com/topic/224699-radio-box-to-display-database-data-in-textbox/#findComment-1160877 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.