I am working on a php page which contains bits of javascript, html and php code.
One of the features of my programme offers an inputbox and a click button(which is of type "submit" )
The user enters a string (for example: "test") and clicks the button ,then a new php page opens displaying the output in a textarea.
Here is the code for the textarea:
<textarea name="Answerfield" id="ta" name="ta"> <?php echo $Mark; ?> </textarea>
As you can see there is a php variable in the textarea that will just print whatever is defined by $Mark
I have written a javascript function called getMark which basically assignes a constant JS variable (an integer) to a specific a specific string of character.
This JS code works
<script language=Javascript>
var m10 = 10;
var m20 = 20;
var m30 = 30;
function getMark(input){
var inputMark = <?php echo $Mark; ?>";
var p ="";
if (input == "test"){
p= m10 + " %";
}
document.getElementById("ta").innerHTML = p;
document.f.ta.value = "p";
return p;
}
</script>
What I am trying to achieve is to assign the getMark Javascript function to my $Mark PHP variable so that if I type "test" in the inputbox and it would print "10%" in the textarea.
I have created a JS variable which would link the getMark function to $Mark :
var inputMark = <?php echo $Mark; ?>";
Here is the line of code of the $Mark variable:
<?php
$Mark = "?><script language=javascript>document.write('inputMark');
</script><?php";
?>
Obviously, it just prints "?><script language=javascript>document.write('inputMark');
</script><?php" in the textarea and ignores the inputMark variable which is linked to $Mark in the Javascript
Would you know what I need to do so that the GetMark javascript function could be assigned to the PHP variable $Mark?
<?php $Mark= ?>
Result , I have tried echo commands mixed with javascript doc.writes and I can manage to assign a php var to javascript var but not the other way around.I read something about having to recall the same form but I cant get the syntax correct.
I am new to php and I must admit I am stuck with this rather silly problem!
Thanks in advance for your precious advice,
Kalou

New Topic/Question
Reply



MultiQuote




|