So I have a form.php with 3 input:a(textbox), b(textbox), c(textbox) Can someone tell me what's this sentence mean and what code should I write to make this happen?
"c contain the 1st letter of a and b, c is generated on page submit by a javascript function"
^ Can someone give me an simpler, clearer expression for this sentence?
I can write for the "1st letter" part but I'm not sure about the trigger when press submit and that 2nd phrase. Should I
_write javascript in the php? (which doesn't work, I keep getting error, even when I use echo)
or
_have a javascript.js like a External css? (never try before)
Here's my code:
<?php
$result= 0;
if(isset($_REQUEST["submit"]))
{
if(isset($_POST["submit"]))
{
$result= $_POST["c"];
}}
?>
<form id="test" action="<?php echo $_SERVER['PHP_SELF']; ?>" method= "POST">
<p>
a <input type="text" name= "a" value="Alex" />
b <input type="text" name= "b" value="Phan" />
c <input type="text" name= "c" value= "<?php echo $result ?>" />
<input type="submit" name= "submit" onclick= "getc();" />
</p>
<script type="text/javascript">
function getc()
{
var firsta = document.getElementsByName("a")[0].value.charAt(0);
var firstb = document.getElementsByName("b")[0].value.charAt(0);
var c;
document.getElementsByName("c")[0].value= firsta + firstb;
}
</script>
</form>
(This code is an update for the answer)
Turn out the javascript didn't work because I tested it on browser, it worked after I uploaded it on the database. Also it doesn't work when I put it like .... ?> either.