PHP Varibles to Javascript for repeating textareas
Posted: Thu May 13, 2004 5:31 am
I am having a problem.
Here is a javascript I have adapted. Its from NOWv1.2.3 JS TextControls.
Currently it only works on the textarea: document.edit.text1. I need it to be applied to each of the text boxes which are constructed thus:
As you can see, (hopefully), I need to pass the variable: $i_desc_var back to the javascript so it knows where to insert the tags.
I am totally lost how I can dynamically assign the correct textarea. Still a newb to be honest. I have a vague feeling that something like: document.edit.eval(from_php) might be the key.
So in summary I need the PHP to pass the variable '$i_desc_var' back to the javascript so it effectively writes:
insertAtCursor(document.edit.$i_desc_var , format1 + text + format2);
Here is a javascript I have adapted. Its from NOWv1.2.3 JS TextControls.
Code: Select all
function insertAtCursor(myField, myValue)
{
//IE support
if (document.selection)
{
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0')
{
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
}
else
{
myField.value += myValue;
}
}
browser = navigator.appName;
if (browser == "Netscape")
{
function format(from_php,format1, format2)
{
var text = prompt('Enter text to format:','');
if (text != null)
{
getSel();
insertAtCursor(document.edit.text1, format1 + text + format2);
}
else
{
return;
}
}
}
else
{
function getSel()
{
if (document.selection) txt = document.selection.createRange().text;
else return;
return txt;
}
function format(from_php,format1, format2)
{
getSel();
insertAtCursor(document.edit.text1, format1 + txt + format2);
}
}Code: Select all
<?
####################################################################################
####################################################################################
####################################################################################
for($i = 1 ; $i < 31 ; $i++):
$i_name_var = 'TC' . $i . '_NAME';
$i_desc_var = 'TC' . $i . '_DESC';
?>
<tr><td colspan="2"> </td></tr>
<tr valign="middle">
<td width="100">Name:</td>
<td><input type="text" name="<?=$i_name_var?>" class="t" style="width:90%;" value="<?=$cArrї0]ї$i_name_var]?>"></td>
</tr>
<tr valign="top">
<td>Description:</td>
<td><p>
<textarea name="<?=$i_desc_var?>" style="width:90%;" rows="7" class="t"><?=$cArrї0]ї$i_desc_var]?>
</textarea>
<br><input type="button" name="bold" Value=" b " OnMouseDown='format($i_desc_var,"<b>", "</b>")'>
<input type="button" name="italics" Value=" i " OnMouseDown='format($i_desc_var,"<i>", "</i>")'>
<input type="button" name="underline" Value=" u " OnMouseDown='format($i_desc_var,"<u>", "</u>")'></p>I am totally lost how I can dynamically assign the correct textarea. Still a newb to be honest. I have a vague feeling that something like: document.edit.eval(from_php) might be the key.
So in summary I need the PHP to pass the variable '$i_desc_var' back to the javascript so it effectively writes:
insertAtCursor(document.edit.$i_desc_var , format1 + text + format2);