Forum Moderators: coopster

Message Too Old, No Replies

Need help with PHP code for my form

I need to add some radio buttons to my form

         

chrisN

7:01 am on May 29, 2005 (gmt 0)

10+ Year Member



Hello,
I need help with my PHP code. Here is a part of it and what I want to do is to add radio buttons to the form. When I select the radio button, it should fill in text into the textarea, for example the word “testText”.
Thank you in advance.

<div align="center">
<font size="4" color="<?=$title_color?>"><b><?=$title?></b></font>
<form method="post" action="<?=$PHP_SELF?>">
<input type="hidden" name="do" value="add">
<table width="460" border="0" cellspacing="1" cellpadding="5">
<tr bgcolor="<?=$table_content_1a?>">
<td>
<textarea name="vcomment" cols="40" rows="7" wrap="virtual"></textarea>
</td>
</tr>
<tr bgcolor="<?=$table_content_1b?>">
<td>
<div align="center">
<font size="2">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
<input type="button" value="Back" onclick="window.location='<?="$PHP_SELF?page=$page"?>'">
</font>
</div>
</td>
</tr>
</table>
</form>
</div>

mcibor

7:06 pm on May 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can write the text with javascript onselect radio button. Or with php:

<textarea name="vcomment" cols="40" rows="7" wrap="virtual"><?php if(isset($_POST["radio"])) echo $_POST["radio"];?></textarea>

<input type="radio" name="radio" value="test1">
<input type="radio" name="radio" value="test2">

I'm not sure what you want to achieve with that, but this will put selected radio into textarea
Michal Cibor

chrisN

8:45 pm on May 29, 2005 (gmt 0)

10+ Year Member



Thanks, Michal. I did that and for some reason it doesn't work: I don't get the text in the textarea. But you understood the idea correctly. Basically I'm just submitting same text line often and I wanted to automate it, instead of typing it over and over again.

<div align="center">
<font size="4" color="<?=$title_color?>"><b><?=$title?></b></font>
<form method="post" action="<?=$PHP_SELF?>">
<input type="hidden" name="do" value="add">
<table width="460" border="0" cellspacing="1" cellpadding="5">
<tr bgcolor="<?=$table_content_1a?>">
<td>
<textarea name="vcomment" cols="40" rows="7" wrap="virtual"><?php if(isset($_POST['radio'])) echo $_POST['radio'];?></textarea>
</td>
</tr>
<tr bgcolor="<?=$table_content_1b?>">
<td>
<div align="center">
<font size="2">
<input type="submit" value="Submit">
<input type="reset" value="Reset">
<input type="button" value="Back" onclick="window.location='<?="$PHP_SELF?page=$page"?>'"><br><br>
<input type="radio" name="radio" value="test1"> test1<br>
<input type="radio" name="radio" value="test2"> test2<br>
</font>
</div>
</td>
</tr>
</table>
</form>
</div>

mcibor

8:52 pm on May 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't understand. I copied and pasted exactly the above code and it worked fine. See the source code of yours, maybe there's a spelling mistake

Best regards
Michal Cibor

chrisN

9:57 pm on May 29, 2005 (gmt 0)

10+ Year Member



Hmmm... I can't find the problem. It just doesn't work.

chrisN

10:41 pm on May 29, 2005 (gmt 0)

10+ Year Member



Michal, maybe javaScript will work? Can you, please, help me with that?

mcibor

11:41 am on May 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<SCRIPT ... bla bla
<!--
function js_text(what)
{
document.getElementById("text_area").value = what;
}
//-->
</script>
</head>
...

<textarea name="text_area" id="text_area"></textarea>
...
<input type="radio" name="radio" onclick="js_text('test1')" value="test1">
...

This should work. If you use mozilla I recommend using javaScript consol
Best regards
Michal Cibor

PS. Have you tried looking at the source code?