Note that there are some explanatory texts on larger screens.

plurals
  1. POinput-button to textarea and writingorder
    primarykey
    data
    text
    <p>I'm stuck making a simple chat-function. There are two problems i have with my code:</p> <ol> <li>I want the new posts to appear on top in the textfile.</li> <li>I want the input-buttons to write some html-code to the textarea, to make it easier to formate the text on use.</li> </ol> <p>Here is the code:</p> <pre><code>&lt;script type="text/javascript"&gt; forma1 = "&lt;B&gt; &lt;/B&gt;" forma2 = "&lt;font color="#B2E0B2"&gt; &lt;/font&gt;" forma3 = "&lt;font color="#C2E0FF"&gt; &lt;/font&gt;" forma4 = "&lt;font color="#FFC2C2"&gt; &lt;/font&gt;" &lt;/script&gt; &lt;form method="post"&gt; &lt;div align="center"&gt; &lt;input name="navn" type="text" size="30" style="color:#68748D;" value="Navn" onfocus="if (this.value == 'Navn') this.value = '';"/&gt; &lt;input type="button" onkeypress="form1('area');"/&gt; &lt;input type="button" onkeypress="form2('area');"/&gt; &lt;input type="button" onkeypress="form3('area');"/&gt; &lt;input type="button" onkeypress="form4('area');"/&gt; &lt;br&gt; &lt;textarea name="txt" cols="55" rows="5" id="area"&gt;&lt;/textarea&gt; &lt;br&gt;&lt;br&gt; &lt;input type="submit" value="Send" name="submit" class="a" /&gt; &lt;/div&gt; &lt;?php if ( isset( $_POST[ 'submit' ] ) ) { $dude = $_POST ['navn']; $time = gmdate("M d Y H:i:s",time()+(2*60*60)); $com = $_POST['txt']; $fp = $file = fopen( "msgs.txt", "a"); fwrite($file, $time); fwrite($file, "&lt;br&gt;"); fwrite($file, '&lt;font color="#68748D" style="font-weight:800;" size="+2"&gt;'); fwrite($file, $dude); fwrite($file, '&lt;/font&gt;'); fwrite($file, "&lt;br&gt;"); fwrite($file, $com); fwrite($file, "&lt;br&gt;________________________________________________________________________&lt;br&gt;" ); fclose($fp); echo '&lt;script type="text/javascript"&gt;window.location ="";&lt;/script&gt;'; } ?&gt; &lt;br&gt; &lt;/form&gt; &lt;font&gt;&lt;b&gt;&lt;p&gt;Output: &lt;/p&gt;&lt;/b&gt;&lt;/font&gt; &lt;fontcolor="#000" size="2"&gt; &lt;?php if (file_exists("msgs.txt")) { $file = fopen( "msgs.txt", "r" ); echo fread( $file, filesize( "msgs.txt" ) ); fclose( $file ); } ?&gt; &lt;/font&gt; </code></pre> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload