Aktuell benutztes Formularfeld übergeben

crsakawolf

Erfahrenes Mitglied
Hi,

ist es möglich, das ich wenn ich einen Knopfdrücke, das aktuelle Inputfeld welches ich zuvor ausgewählt habe zu übergeben?

Code:
<?
echo "<script type='text/javascript'>
         function underlining()
         {
          document.hausmitteilungsform.focus.value = document.hausmitteilungsform.ersteller.value + 'test';
         }

     </script>";
echo "<form action='<?$PHP_SELF?>' method='POST' name='hausmitteilungsform'>
<table border='0'>
<tr>
    <td width='90'>Datum:</td>
    <td><input type='text' name='datum' size='10' maxlength='10'></td>
    <td width='90'>Nummer:</td>
    <td><input type='text' name='nummer' size='7' maxlength='7'></td>
    <td rowspan='7'>
        <input style='width:40px;text-decoration:underline' onclick='underlining()' type='button' value='u'><br>
        <input style='width:40px;font-weight:bold' type='button' value='b'><br>
        <input style='width:40px;' type='button' value='x²'><br>
        <input style='width:40px;' type='button' value='Link'><br>
        <input style='width:40px;' type='button' value='Bild'>
    </td>
</tr>
<tr>
    <td width='90'>Ersteller:<br><font style='font-size:9px;color:red;'></font></td>
    <td width=''><input type='text' name='ersteller'></td>
    <td width='90'>Referat:<br><font style='font-size:9px;color:red;'></font></td>
    <td><input type='text' name='referat'></td>
</tr>
<tr>
    <td width='90'>An:</td>
    <td colspan='3'><textarea cols='60' rows='5' name='an'></textarea></td>
</tr>
<tr>
    <td width='90'>Titel:</td>
    <td colspan='3'><input type='text' name='titel' size='79'></td>
</tr>
<tr>
    <td width='90'>Text:</td>
    <td colspan='3'><textarea cols='60' rows='15' name='text'></textarea></td>
</tr>
<tr>
    <td colspan='4' align='center'>Eintrag unter 'Neues'&nbsp;&nbsp;  <input type='checkbox' name='neues' value='1' checked='checked'></td>
</tr>
<tr>
    <td colspan='4' align='center'><input type='submit' name='send' value='Speichern'></td>
</tr>
</table>
</form>";


if(!empty($_POST['send']))
{
 echo $_POST['datum']."<br>";
 echo $_POST['nummer']."<br>";
 echo $_POST['ersteller']."<br>";
 echo $_POST['referat']."<br>";
 echo $_POST['an']."<br>";
 echo $_POST['titel']."<br>";
 echo str_replace("\n","<br>",$_POST['text']).'<br>';
 echo $_POST['neues'].'<br>';
}

?>
 
Also ich setz den Mauszeiger vorher rein ^^

So war das gemeint,

hab halt 2 inputs / textfelder, die ich gern mit einer Leiste (für B, U usw) befüllen will, jenachdem wo der cursor sitzt ..
 
Ahso, Ich dachte du willst nur ein bestimmtes Feld senden :)

Du könntest bspw. jedes mal, wenn du in eines dieser Felder klickst(onfocus), dies Feld in einer globalen Variable speichern....auf diese Variable greifst du dann später zu.
 
ach ich hasse js xD

Code:
var fokusiert;

function sFocus(area)
{
 fokusiert = area;
 document.hausmitteilungsform.text.value = document.hausmitteilungsform.text.value+fokusiert;
}
<td colspan='3'><textarea cols='60' rows='15' name='text' onFocus='sFocus('text')'></textarea></td>

Es will nicht klappen :/

Also er übergibt der Var fokusiert nicht wirklich, das es text ist :/
 
Übergebe nicht irgendeinen String, sondern das Feld selbst:

Code:
onfocus='fokusiert=this'

Kurzer Test:

Code:
function underlining()
         {
         if(typeof fokusiert!='undefined')alert(fokusiert.value);
         }
 
Danke dir vielmals. Es klappt.

Hätte noch ein Problem, hoffe es ist okay, wenn ich es hier reinposte ...

Ich benötige eine möglichkeit. um Markierten text herum etwas zu schreiben.

also wie hier die bb-codes für bold usw.
das dann {b}text{/b} herum steh.

für ie habe ich eine möglichkeit gefunden, jedoch FF schaffts net.

Hab das Forum auch schon durchsucht aber nix 100% treffendes gefunden :/
 
ach man :( warum geht sowas net mit php ...


Code:
<?
echo "<script type='text/javascript'>
<!--
function format(strTag)
{
objEditor = document.hausmitteilungsform.fokusiert;
blnIe     = document.selection;
blnMoz    = (objEditor.selectionStart || objEditor.selectionStart == '0');
if(blnIe)
    {
        objEditor.focus();
        strTxt=document.selection.createRange().text
        if(strTxt=='')
            {
                strTxt=prompt('Text eingeben','');
                if(!strTxt||strTxt=='')return;
            }
        document.selection.createRange().text='['+strTag+']'+strTxt+'[\/'+strTag+']';
        document.selection.createRange().select();
    }
else if (blnMoz)
        {
                intStart = objEditor.selectionStart;
                intEnd = objEditor.selectionEnd;

                strTxt=String(objEditor.value).substring(intStart,intEnd);
                if(strTxt=='')
            {
                strTxt=prompt('Text eingeben','');
                if(!strTxt||strTxt=='')return;
            }
                objEditor.value = String(objEditor.value).substring(0, intStart) +'['+strTag+']'+strTxt+'[\/'+strTag+']'+ String(objEditor.value).substring(intEnd, objEditor.value.length);
                objEditor.focus();
        }
else
        {
                strTxt=prompt('Text eingeben','');
        if(!strTxt||strTxt=='')return;
        objEditor.value+='['+strTag+']'+strTxt+'[\/'+strTag+']';
        }
}
//-->
</script>";
echo "<form action='".$PHP_SELF."' method='POST' name='hausmitteilungsform'>
<table border='0'>
<tr>
    <td width='90'>Datum:</td>
    <td><input type='text' name='datum' size='10' maxlength='10'></td>
    <td width='90'>Nummer:</td>
    <td><input type='text' name='nummer' size='7' maxlength='7'></td>
    <td rowspan='7'>
        <input style='width:40px;text-decoration:underline' onclick='format('u')' type='button' value='u'><br>
        <input style='width:40px;font-weight:bold' onclick='bolding()' type='button' value='b'><br>
        <input style='width:40px;' type='button' onclick='suping()' value='x²'><br>
        <input style='width:40px;' type='button' value='½'><br>
        <input style='width:40px;' type='button' value='Link'><br>
        <input style='width:40px;' type='button' value='Bild'>
    </td>
</tr>
<tr>
    <td width='90'>Ersteller:<br><font style='font-size:9px;color:red;'>(für Hausmitteilung)</font></td>
    <td width=''><input type='text' name='ersteller' onFocus='fokusiert=this'></td>
    <td width='90'>Referat:<br><font style='font-size:9px;color:red;'>(für Hausmitteilung)</font></td>
    <td><input type='text' name='referat' onFocus='fokusiert=this'></td>
</tr>
<tr>
    <td width='90'>An:</td>
    <td colspan='3'><textarea cols='60' rows='5' name='an' onFocus='fokusiert=this'></textarea></td>
</tr>
<tr>
    <td width='90'>Titel:</td>
    <td colspan='3'><input type='text' name='titel' size='79' onFocus='fokusiert=this'></td>
</tr>
<tr>
    <td width='90'>Text:</td>
    <td colspan='3'><textarea cols='60' rows='15' name='textfeld' onFocus='fokusiert=this'></textarea></td>
</tr>
<tr>
    <td colspan='4' align='center'>Eintrag unter 'Neues'&nbsp;&nbsp;  <input type='checkbox' name='neues' value='1' checked='checked'></td>
</tr>
<tr>
    <td colspan='4' align='center'><input type='submit' name='send' value='Speichern'></td>
</tr>
</table>
</form>";


if(!empty($_POST['send']))
{
 echo $_POST['datum']."<br>";
 echo $_POST['nummer']."<br>";
 echo $_POST['ersteller']."<br>";
 echo $_POST['referat']."<br>";
 echo $_POST['an']."<br>";
 echo $_POST['titel']."<br>";
 echo str_replace("\n","<br>",$_POST['text']).'<br>';
 echo $_POST['neues'].'<br>';
}

?>
 
Zurück