Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #20817

Re: Script stopped working when I altered form type

Message-ID <5682005.goIip4NAP1@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2013-07-28 18:15 +0200
Subject Re: Script stopped working when I altered form type
Newsgroups comp.lang.javascript
References <dwj9j8e4wvez$.158zrqmvkzmci$.dlg@40tude.net>

Show all headers | View raw


Mad Hatter wrote:
^^^^^^^^^^
Please get a real name.

> First off I'm absolutely useless at javascript.

Good, because there is no such programming language:

<http://PointedEars.de/es-matrix>

> I like playing around with PHP. I had a working PHP script which had a
> form which included a text box. I used the following script which I found
> somewhere on the net a long time ago to insert text depending on what
> button was pressed:-
> 
> <SCRIPT LANGUAGE='JavaScript'>
>   <!--
>   function insertcode(newcode) {
>   document.newtopic.msg.value = document.newtopic.msg.value+newcode;
> 
>   }
>   //-->
> </SCRIPT>

Always validate your generated markup: <http://validator.w3.org/>

And the proper syntax is:

  <script type="text/javascript">
    function insertcode (newcode)
    {
      document.forms["newtopic"].elements["msg"].value += newcode;
      return false;
    }
  </script>
 
> and an assortment of buttons along the lines of :-
> <a href="javascript:insertcode('[i]TEXT[/i] ')"><img src="b2.jpg"
> height="15" alt="Italic" border="0" /></a>

  <a href="#" onclick="return insertcode('[i]TEXT[/i] ')"
     ><img src="b2.jpg" height="15" alt="Italic" border="0"></a>

There are even better ways, of course.  Consider generated “button” 
elements, where no navigation will take place when there is insufficient 
client-side script support (as the buttons will not be generated then in the 
first place).
 
> This worked fine when the form was the following type :-
> 
> <form action="ep.php" method="POST" name="newtopic">
> 
> I've just had to alter the form type to include file uploads so forms are
> now :-
> <form ENCTYPE='multipart/form-data' action='ep.php' method='POST'
> name='newtopic'>
> 
> The text input box hasn't altered  :-

It should have been.

> <textarea rows="10" cols="50" name="msg" wrap="virtual"><?php echo
> "$reply"; ?></textarea>

Variable expansion is pointless there.  What is missing is escaping of 
output to prevent code injection:

  <textarea rows="10" cols="50" name="msg" wrap="virtual"><?php
    echo htmlspecialchars($reply);
  ?></textarea>
 
> Since I've altered to the ENCTYPE='multipart/form-data' form input my
> buttons no longer work. Nothing at all. Can anyone tell me why and suggest
> a fix please.

Adding the “enctype” attribute alone does not cause this problem.  There is 
relevant code that you are not showing.  Please post the public URL of a 
reduced testcase.

<http://jibbering.com/faq/#posting>
<http://PointedEars.de/faq#posting>

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Script stopped working when I altered form type Mad Hatter <colin@class31.co.uk> - 2013-07-27 15:22 +0100
  Re: Script stopped working when I altered form type "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-07-27 17:13 +0200
    Re: Script stopped working when I altered form type Mad Hatter <colin@class31.co.uk> - 2013-07-27 17:35 +0100
      Re: Script stopped working when I altered form type "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-07-27 23:54 +0200
        Re: Script stopped working when I altered form type Mad Hatter <colin@class31.co.uk> - 2013-07-28 22:32 +0100
    Re: Script stopped working when I altered form type Eric Bednarz <bednarz@fahr-zur-hoelle.org> - 2013-07-29 00:56 +0200
  Re: Script stopped working when I altered form type Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-07-28 18:15 +0200

csiph-web