Urgent help with radio button working with text field working in php

Okay I’m not sure how to put this right… Let me try to explain.

I want to use one text box and the info inside it will vary depending on radio button selection, screen shot…

if this is the text box

<input type="text" name="i" id="nomeff" value="<?php ?>" size="5" />

and these are the radio button

<input type="radio" name="rate" value="i">Effective Value <input type="radio" name="rate" value="r">Nominal value

how are they going to integrate.

>>>>>>>>>>>
Previously I had 2 text boxes so I coded with php in that way…

The php code



<?php
if(isset($_REQUEST['submit'])) {
	define("e", "2.71828183");
	$i=trim($_REQUEST['i'])/100;
	$r=trim($_REQUEST['r'])/100;
	
	//to accomodate different compounding periods including "other"
	if(empty($_REQUEST['n2'])){
		$n=trim($_REQUEST['n']);
		}else{
		$n=trim($_REQUEST['n2']);
	}
	// Effective value Calculation
	if(empty($_REQUEST['r'])){
		if($n == "Continuous" ){
			$result=(pow(e,$i)-1)*100;}
		else{
			$result=((pow(1+($i/$n),$n))-1)*100;}
			
			echo "The effective value is ".number_format(round($result, 3), 3)."%";
	}
	// Nominal value Calculation
	if(empty($_REQUEST['i'])){
		if($n == "Continuous"){
			$result=((log10($r+1))/(log10(e)))*100;}
		else{
			$result=((pow(($r+1), 1/$n)-1)*$n)*100;}
			
			echo "The nominal value is ".number_format(round($result, 3), 3)."%";	
	}
}
?>

and this the text box html…

<tr>
			<td>Nominal annual interest rate:</td><td><input id="id_i" type="text" name="i" value="<?php if(!empty($_REQUEST['i'])){ echo trim($_REQUEST['i']);} ?>" size="5" /> <span class=nt>%</span></td>
		</tr>
		<tr>
		  <td>Effective Interest Rate:</td><td><input id="id_i" type="text" name="r" value="<?php if(!empty($_REQUEST['r'])){ echo trim($_REQUEST['r']);} ?>" size="5" /> <span class=nt>%</span></td>
		</tr>

Now, how can I serve the same purpose with radio buttons and a text box instead of 2 text boxes,
I hope i was able to explain it some what. Any help highly appreciated. :slight_smile:

Instead use

<input type="number" name="i" id="nomeff" value="<?php echo $_REQUEST['i'] ?>" size="5">

Older browsers will treat number as a text field anyway. Newer ones will filter the inputs automatically, smartphones visiting the site will present a numeric keypad instead of a full keyboard.

and these are the radio button

<input type="radio" name="rate" value="i">Effective Value <input type="radio" name="rate" value="r">Nominal value

how are they going to integrate.

If neither radio button is clicked, $_REQUEST[‘rate’] will not be set. Otherwise, it will have the value of the radio button that was checked when the form was submitted.

I would recommend setting a default with the checked attribute and using the label tag for the radio button’s label.

<input type="radio" name="rate" value="i" checked id="effective"><label for="effective">Effective Value</label>

The for attribute of label links it to the radio button. The value of the attribute must match the id of the radio button. Once set, it allows the radio button to be checked by clicking the label.

Although these solutions didn’t address my main problem, they are still priceless advise. I guess I was not able to articulate my self well. Any way I was able to solve the main problem.
Thanks

number seems to doesn’t accept decimals. What can be done here?

Got it, step=“any” attribute…