Jump to content

Using Radio Option To Hide/show Div Tag Within Php After Clicking The Submit Button


Recommended Posts

Hello,

 

I have 2 radio options, one for a new client and one for a returning client and there respective div tags(Div2 - new client and Div2 - returning client)

 

when radio option 1 is selected div1 appears - works

when radio option 2 is selected div2 appears - works

 

problem:

if radio option 2 is selected the div2 appears but if the page is submitted the returning page still has radio opiton 2 selected but div1 is displayed.

 

need:

1. radio opiton 1 selected to display div1 and submitted. The returning page should have both radio option 1 and div1 selected

2. radio opiton 2 selected to display div2 and submitted. the returning page should have both radio option 2 and div2 selected.

 

Any help you can provide would be greatly appreciated.

 

Thanks you,

 

<head>
<script type="text/javascript" >
$(document).ready(function ()
{ $('#div2').hide();
$('#id_radio1').click(function ()
{ $('#div2').hide('fast');
$('#div1').show('fast');
});
$('#id_radio2').click(function ()
{ $('#div1').hide('fast');
$('#div2').show('fast');
});
});
</script>
</head>


<body>

<?php
if(isset($_POST['btnsave']))

{ $userIdField = $_POST['userIdField'];
$userPassword = $_POST['passwordField'];
$radopt1 = $_POST['radopt'];
$radopt2 = $_POST['radopt'];
if($_POST['radopt'] == "1")
{ echo "STAGE: testing: inside new cient"; }	
else if($_POST['radopt'] == "2")
{ echo "Testing Inside returning client";}
}
?>

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="POST">
<br/>
<center>
<?php echo "Test: Radio option==>:". $_POST['radopt']; ?>
<div align="center" style="border:2px solid red; width:600px; height:110px;" >
<input id="id_radio1" type="radio" value = "1" name="radopt" checked="checked" <?php if ($radopt1 == "1") { echo 'checked="checked"'; } ?> /> New Client
<input id="id_radio2" type="radio" value = "2" name="radopt" <?php if ($radopt2 == "2") { echo 'checked="checked"'; } ?> /> Returning Client

<br/>
<div id="div1" style=" border:2px solid blue; width:500px;">
<table boarder="1">
 <tr>
 <th>userId:<input type = "text" name = "userIdField" value = "<?PHP if(!empty($_POST['userIdField'])) {echo $_POST['userIdField'];} else { echo '';} ?>" /> </th>
 <th>Password:<input type = "text" name ="passwordField" id = "passwordField" value = "" /> </th>
 </tr>
 <tr>
 <th>Email address:<input type = "text" id = "passwordField" value = "E-Mail address" /> </th>
 <th>re-enterPassword: <input type = "password" id = "passwordField" value = "" /> </th>
 </tr>
</table>
</div>
<div id="div2" style=" border:2px solid green; width:500px; height:40px;">
<table boarder="1">
 <tr>
 <th>UserId:<input type = "text" id = "userIdField" value = "User Id" /> </th>
 <th>Password:<input type = "text" id = "passwordField" value = "" /> </th>
 </tr>
</table>
<br/>	
</div>
</div>

<div>	
<br/><br/>
<button type="submit" name="btnsave" value ="" >Submit Project</button>
</div>
</center>
</form>



</body>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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