Click to See Complete Forum and Search --> : Function Help!


RobRocker
01-06-2007, 09:18 PM
Hello,

I would like to create a function that when a user clicks a radio button, it sends a value to the function and then it outputs some table information.

For instance when a user clicks a "Yes" radio I want it to add two rows to the table.

Here is what I tried.

function rollOverFunction($change){
$check = $change;
if($check == "Yes"){
$output = "<tr><td>Prior Custodian/Plan Name</td><td></td></tr><tr><td>Expected Rollover Amount $</td><td></td></tr>";
}
}

<input name="rollOver" type="radio" value="Yes" onFocus="<?php rollOverFunction('Yes') ?>"> No <input name="rollOver" type="radio" value="No" checked="checked" onFocus="<?php rollOverFunction('No') ?>">

Then my output code is:

<?php echo $output; ?>

Thanks for the help.

dougal85
01-06-2007, 09:56 PM
PHP is a serverside programming language. This means that all the code needs to be executed before its outputted onto the clients machine.

To do what you want to do you will need to use some Javascript. It can be done is straight javascript or you can always look into the hype-word of late; AJAX

pcthug
01-07-2007, 10:13 AM
PHP and AJAX aren't required as there is nothing in your code that can't be done with pure Javascript. Look into the Javascript InnerHTML directive.

dougal85
01-07-2007, 10:33 AM
I had only added AJAX out of possible interest with further reading.

Here is something to get you started that i had lying around.;



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>

<script language="javascript" type="text/javascript">

function rollOver(){

document.getElementById('TextArea1').innerHTML = "test";

}

</script>

</head>
<body>

<input id="Radio1" type="radio" onfocus="rollOver();" />

<textarea id="TextArea1" cols="20" rows="2"></textarea>

</body>
</html>

RobRocker
01-07-2007, 08:09 PM
Thanks.