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


Groups > comp.lang.javascript > #20809 > unrolled thread

Script stopped working when I altered form type

Started byMad Hatter <colin@class31.co.uk>
First post2013-07-27 15:22 +0100
Last post2013-07-28 18:15 +0200
Articles 7 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#20809 — Script stopped working when I altered form type

FromMad Hatter <colin@class31.co.uk>
Date2013-07-27 15:22 +0100
SubjectScript stopped working when I altered form type
Message-ID<dwj9j8e4wvez$.158zrqmvkzmci$.dlg@40tude.net>
Hi All

First off I'm absolutely useless at javascript. 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>

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>

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  :-
<textarea rows="10" cols="50" name="msg" wrap="virtual"><?php echo
"$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. 



[toc] | [next] | [standalone]


#20810

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-07-27 17:13 +0200
Message-ID<XnsA20AAF3F14F2Aeejj99@194.109.133.133>
In reply to#20809
Mad Hatter wrote on 27 jul 2013 in comp.lang.javascript:

> <SCRIPT LANGUAGE='JavaScript'>

code from the last century

>   <!--

code from the last century

>   function insertcode(newcode) {
>   document.newtopic.msg.value = document.newtopic.msg.value+newcode;
> 
>   }
>   //-->

code from the last century

> </SCRIPT>

You are using code from the last century, 
and even then only more or less reliable in prehistoricIE!!

Try:

<script type='text/javascript'>
function insertcode(newcode) {
  document.forms.newtopic.elements.msg.value += newcode;
};
</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>

height="15" prehistoric, use CSS
/> xhtml, why?

href="javascript: use onclick when you want to click an image!!

Better use:

<img 
src="b2.jpg" style='height:15px' alt="Italic" 
onclick='insertcode("[i]TEXT[/i]")'>

> 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'>

I see no clientside difference, both work fine with method='GET', 
both with and without your encoding directive.

Better use 'application/x-www-form-urlencoded'.

You should only use 'multipart/form-data' when you have an <input
type="file">, and perhaps not even then. 

Why?
<http://stackoverflow.com/questions/4526273/what-does-enctype-multipart-f
orm-data-mean> 

> The text input box hasn't altered  :-
> <textarea rows="10" cols="50" name="msg" wrap="virtual"><?php echo
> "$reply"; ?></textarea>

Please strip the code of parts that don't matter, 
like the php that is also off topic on this NG.



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#20811

FromMad Hatter <colin@class31.co.uk>
Date2013-07-27 17:35 +0100
Message-ID<py4oc3i7za68$.yk4iffxnf639.dlg@40tude.net>
In reply to#20810
Hi

On Sat, 27 Jul 2013 17:13:38 +0200, Evertjan. wrote:

> Mad Hatter wrote on 27 jul 2013 in comp.lang.javascript:
> 
>> <SCRIPT LANGUAGE='JavaScript'>
> 
> code from the last century
Well, the last century was only 13 years ago ;-)

> 
> You are using code from the last century, 
> and even then only more or less reliable in prehistoricIE!!
> 
> Try:
> 
> <script type='text/javascript'>
> function insertcode(newcode) {
>   document.forms.newtopic.elements.msg.value += newcode;
> };
> </script>

Okay tried that

> 
> href="javascript: use onclick when you want to click an image!!

I am clicking on an image to insert the text
> 
> Better use:
> 
> <img 
> src="b2.jpg" style='height:15px' alt="Italic" 
> onclick='insertcode("[i]TEXT[/i]")'>

I tried this with the above and nothing :-(

I'm probably doing something wrong here but I can't see what. 

[toc] | [prev] | [next] | [standalone]


#20812

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2013-07-27 23:54 +0200
Message-ID<XnsA20AF320EECC2eejj99@194.109.133.133>
In reply to#20811
Mad Hatter wrote on 27 jul 2013 in comp.lang.javascript:

>> code from the last century
> Well, the last century was only 13 years ago ;-)

This is no joke!

The browsers of that time do no longer exist for the users.

> I tried this with the above and nothing :-(
> 
> I'm probably doing something wrong here but I can't see what. 

Yes, you are not using my code, because that was tested ok,
you inserted it in your wrong code, I presume.

Throw out all the code that doesn't concern the issue at hand,
like php and parts you do not need,
then test if the error still exists.

Try to understand the code completely.

If the error persists show us the code instead of describing parts. 

[Please use a signature.]

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#20826

FromMad Hatter <colin@class31.co.uk>
Date2013-07-28 22:32 +0100
Message-ID<1dlmxejhu37d7$.n8blc6kofva1.dlg@40tude.net>
In reply to#20812
On Sat, 27 Jul 2013 23:54:01 +0200, Evertjan. wrote:

> 
> This is no joke!
> The browsers of that time do no longer exist for the users.

I thought that until I check the logs for my site forum. I run a classic
car web site and we still have members running win95, win2000, IE6, and
even Netscape. I know they should have been kicked off the planet years ago
but some people refuse to change. My father being one of them. He's 85 and
refuses to let me upgrade his PC. On the forum I try to explain the
vulnerabilities of using the old software but it falls on deaf ears :-(
> 
> Yes, you are not using my code, because that was tested ok,
> you inserted it in your wrong code, I presume.

It was my fault. A little syntax error had crept in. I do apologise. Your
code works fine. Thanks.

-- 
Colin

[toc] | [prev] | [next] | [standalone]


#20827

FromEric Bednarz <bednarz@fahr-zur-hoelle.org>
Date2013-07-29 00:56 +0200
Message-ID<m2li4qnvjh.fsf@nntp.bednarz.nl>
In reply to#20810
"Evertjan." <exxjxw.hannivoort@inter.nl.net> writes:

> Mad Hatter wrote on 27 jul 2013 in comp.lang.javascript:

>> [...]<img src="b2.jpg"
>> height="15" alt="Italic" border="0" /></a>
>
> height="15" prehistoric, use CSS

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-map-element.html#attr-dim-height
Last-Modified: Fri, 26 Jul 2013 23:27:54 GMT

Time sure flies on the interwebs.

[toc] | [prev] | [next] | [standalone]


#20817

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2013-07-28 18:15 +0200
Message-ID<5682005.goIip4NAP1@PointedEars.de>
In reply to#20809
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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web