Wie bekomm ich einen Eintrag per Klick in eine Textbox?

Ralph

Erfahrenes Mitglied
Hallo,

ich habe eine beliebige Anzahl von Inputfeldern (Text), alle haben einen eindeutigen Namen, der auch bekannt ist.

Nun habe ich auf der einen Seite meiner Anwendung eine Tastatureingabe per Maus erstellt. Sprich das Alphabet ist dort aufgelistet und mit einem Klick auf den entsprechenden Buchstaben wird in einem dadrunter liegenden Textfeld der gewünschte Text "gebaut".

Soweit so gut. Das funktioniert alles. Nun muss dieser Textinhalt noch in eines der o.g. Inputfelder übernommen werden. Idee wäre, man klickt auf ein Icon, welches neben jedem dieser Textfelder vorhanden ist. Dort wird dann z.B. die ID übergeben, damit meine neue "Tastatur" weiß, wohin der Inhalt geschrieben werden soll.

Besser und vielleihct auch einfacher zur scripten ist vielleicht folgendes:

Der Text wird direkt in das Inputfeld geschrieben, welches den Focus hat. Weil das kann man doch bestimmt herausfinden, denk ich mal. (Such auch gerad schon fleißig ;)
 
Zuletzt bearbeitet:
Hi ;)

so gerad das Problem gelöst. Habe jetzt an jedem Formularfeld ein Icon, welches mir den Inhalt austauscht. Das ist viel einfacher.

Trotzdem danke.


(Wenn sich trotzdem jemand dran versuchen will kann ich gerne nochmal ausführlicher beschreiben ;)
 
Du könntest es auch mit dem "abschreiben" versuchen.
damit:

onKeyup (bei losgelassener Taste)
Tritt ein, wenn der Anwender eine Taste gedrückt hat und diese wieder loslässt.

Nach JavaScript (Netscape) erlaubt erlaubt in folgenden HTML-Tags:
<input> <textarea>

Nach HTML 4.0 erlaubt in folgenden HTML-Tags:
<a> <abbr> <acronym> <address> <area> <b> <big> <blockquote> <body> <button> <caption> <center> <cite> <code> <col> <colgroup> <dd> <del> <dfn> <dir> <div> <dl> <dt> <em> <fieldset> <form> <h1> <h2> <h3> <h4> <h5> <h6> <hr> <i> <img> <input> <ins> <kbd> <label> <legend> <li> <link> <map> <menu> <noframes> <noscript> <object> <ol> <optgroup> <option> <p> <pre> <q> <s> <samp> <select> <small> <span> <strike> <strong> <sub> <sup> <table> <tbody> <td> <textarea> <tfoot> <th> <thead> <tr> <tt> <u> <ul> <var>



<html><head><title>Test</title>
</head><body>
<form name="Test" action="">
<input type="text" size="30" name="Eingabe"
onKeyup="this.form.Ausgabe.value=this.value"><br>
<input type="text" readonly size="30" name="Ausgabe"><br>
<input type="reset">
</form>
</body></html>
 
PHP:
var act_input;

[...]

<input type="text" name="input1" onFocus="act_input='input1';" onBlur="act_input='';">
In der Eingabefunktion checkst du dann, ob act_input gesetzt ist, wenn ja, dann steht in act_input ja das gerade fokusierte Feld.


//Edit: Machs lieber so:
PHP:
<html>
<head>
<script type="text/javascript">

var act_input = "";

function addChar( str_char ) {
    if (act_input != "") {
        window.document.inpform[act_input].value += str_char;
	window.document.inpform[act_input].focus();
    }
}

</script>
</head>
<body>

<form name="inpform">

<input type="text" name="feld1" size="30" onFocus="act_input='feld1';" onBlur="act_input='feld1';">
<br>
<input type="text" name="feld2" size="30" onFocus="act_input='feld2';" onBlur="act_input='feld2';">

<br><br><br>
<input type="button" value=" A " onClick="addChar('A');">
&nbsp;<input type="button" value=" B " onClick="addChar('B');">
&nbsp;<input type="button" value=" C " onClick="addChar('C');">
&nbsp;<input type="button" value=" D " onClick="addChar('D');">
&nbsp;<input type="button" value=" E " onClick="addChar('E');">

</form>

</body>
</html>
 
Zuletzt bearbeitet von einem Moderator:
Zurück