Jump to content

Radio Buttom for beginner


j_prakash81

Recommended Posts

Hello guyzzz  i'm realy new to PHP. Recently im train my self to code in php with simple radio button but it's not working. the idea....there is a two radio button in my page, when the user chose and click the submit button it should transfer to particuler page.....anybody can help me...

the code goes like this
<?

[color=green]$choise;
$a = "a" ;[/color]
print
"<CENTER>
<table border='0' width='20%'>

<form method='POST' action=$choise.php>

<tr>
  <td colspan='2' >Selection</td>

</tr>
<tr>
  <td width='1%'><input type='radio' name='select' value='a' checked></td>
  <td>A to page A.php</td>
</tr>
<tr>
  <td><input type='radio' name='select' value='b'></td>
  <td>B to page B.php</td>
</tr>"

[color=green]if ($a == select) {
$choise = $a;[/color]print "<tr ALIGN='CENTER'>
<td colspan='2'><input type='submit' value='Submit' name='B1'></td>
</tr>"

[color=green]else {
$choise = $b[/color]print "<tr ALIGN='CENTER'>
<td colspan='2'><input type='submit' value='Submit' name='B1'></td>
</tr>"
}
print "<BR></form></table>";

?>
Link to comment
https://forums.phpfreaks.com/topic/19363-radio-buttom-for-beginner/
Share on other sites

Im A newb aswell but it looks like you aint set your variables up right

and the form is going to a page that dosnt exist because you havnt set $choise to anything, also your coding html in php wrong

for a line of html like wat you have there you need

echo"<td><input type=\'radio\' name=\'select\' value=\'b\'></td>";

think its best if you start again and look for examples on the net
[quote author=j_prakash81 link=topic=106494.msg426345#msg426345 date=1157162754]
what is different between [color=blue]echo[/color] and [color=blue]print[/color] function..
[/quote]

Nothing substantive. You can read all about both in the online manual if you're interested.
if you want the user to click on a radio button, hit submit, and it goes to the same page regardless, but does something based on which radio button was selected, then you would use php. if you want to select 'a' or 'b' radio button, and it takes you to a.php or b.php, you are going to have to do that with javascript.

php is a server side language. all php code is parsed on the server, before anything is sent to your computer.  so you cannot make 'on-the-fly' decisions like that with php.  javascript is a client side language.  you can make 'on-the-fly' decisions using their onfocus, onclick, onblah event handlers to change the action = 'blah.php' in your form. 

since your question looks like the 2nd of the 2, i'm moving this to javascript help.

Archived

This topic is now archived and is closed to further replies.

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