So I have this javascript working:
<script type="text/javascript" language="javascript">
function ChangeText(user)
{
var MyElement = document.getElementById("js_to");
MyElement.value = user;
return true;
}
</script>
And I have a form field:
<input id="js_to" type="text" name="to" value="<?php print($to) ?>">
So I have a "friend list" on the right side of the screen with a list of friends of the user currently logged in:
for($i = 0; $friends[$i]; $i++)
{
?>
<script language="javascript">
var user = <?php print($friends[$i]); ?>;
</script>
<a href="#" onclick="ChangeText(user)"><?php print($friends[$i]); ?></a>
<?php
}
When the user clicks one of these links, that name should appear in the form field, but in order to do that I need to pass the php array element currently going through the loop and set that as the parameter for my ChangeText() function in order to define my user variable...
How do I pass that php variable to the javascript?
<script type="text/javascript" language="javascript">
function ChangeText(user)
{
var MyElement = document.getElementById("js_to");
MyElement.value = user;
return true;
}
</script>
And I have a form field:
<input id="js_to" type="text" name="to" value="<?php print($to) ?>">
So I have a "friend list" on the right side of the screen with a list of friends of the user currently logged in:
for($i = 0; $friends[$i]; $i++)
{
?>
<script language="javascript">
var user = <?php print($friends[$i]); ?>;
</script>
<a href="#" onclick="ChangeText(user)"><?php print($friends[$i]); ?></a>
<?php
}
When the user clicks one of these links, that name should appear in the form field, but in order to do that I need to pass the php array element currently going through the loop and set that as the parameter for my ChangeText() function in order to define my user variable...
How do I pass that php variable to the javascript?