Tags:
create new tag
view all tags

Question

I'm using a form with input fields to add content to the twiki. I also wanna make sure, that certain fields are filled. For that reason I use java script:

function chkForm () {
  if (document.Form.DisplayName.value == "") {
    alert("Please enter display name!");
    document.Formu.DisplayName.focus();
    return false;
  }"

Here the form part:

<form name="Form" onsubmit="return chkForm()" method="get" action="%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%WEB%/">

This works great so far.

Furthermore I include (with

%INCLUDE{"page"}%
) this topic somewhere else, but the java script doesn't work anymore. I won't get any alert messages. After pushing the submit button, the browser forwards me to http://twikitest/twiki/bin/edit/&#8230; This should not happen unless all required fields are filled.

Is this a known issue?

Environment

TWiki version: TWikiRelease04x00x05
TWiki plugins: DefaultPlugin, EmptyPlugin, InterwikiPlugin
Server OS: debian vm
Web server:  
Perl version:  
Client OS: Windows 2000
Web Browser: any (opera, firefox, ie)
Categories: Javascript

-- ThomasEsau - 14 Dec 2006

Answer

ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.

It should work if you include the entire topic (i.e. including the javascript). I do see a typo in the second form reference but i doubt that's your problem.

-- LynnwoodBrown - 14 Dec 2006

I also see a quote at the closing bracket.

Did you set AllowInlineScript in configure?

-- ArthurClemens - 14 Dec 2006

The typo is not the problem. The script works fine, as long as I use it without including it on a different site with INCLUDE{"page"}. To be clear, it does not work on the site where the topic is used with INCLUDE! I also define the span with STARTINCLUDE and STOPINCLUDE (the java script is between these variables).

The checkbox AllowInlineScript is checked in configure.

-- ThomasEsau - 15 Dec 2006

in your code, try changing... %WEB% with %BASEWEB%

-- SteveStark - 16 Dec 2006

Unfortunately it does not change anything!

-- ThomasEsau - 18 Dec 2006

It would not be surprising if the code were overzealous in protecting you from security problems here. As INCLUDE can work on topics and on external html pages, it may well be unconditionall stripping all javascript. I'd probably consider this a bug, especially as TWiki as a whole leans towards allowing you to do interesting things like this smile

-- SvenDowideit - 18 Dec 2006

There are parts of javascript working... For example I'm using javascript to capitalize words to TWikiWords, which works!

-- ThomasEsau - 18 Dec 2006

Are you referencing attached javascript files with %ATTACHURL%/file.js? If so, replace with %PUBURL%/%BASEWEB%/%BASETOPIC%/file.js.

-- PeterThoeny - 18 Dec 2006

No, the javascript is in the body:

<script language="javascript">
<!--
function chkForm () {
  if (document.Form.DisplayName.value == "") {
    alert("Please enter a display name!");
    document.Form.DisplayName.focus();
    return false;
  }
}
//-->
</script>

-- ThomasEsau - 19 Dec 2006

The &#8230 might be because of an extra " in the code. Therefore, try ' instead of "... onsubmit='return chkForm()' method='get' action='%SCRIPTURLPATH%/edit%SCRIPTSUFFIX%/%BASEWEB%/'

Post the complete form code.

-- SteveStark - 26 Dec 2006

I have just been battling with a similar problem, and on inspection of the generated HTML, when a page with Javascript is INCLUDEd, TWiki prefixes delimited CamelCase words with the name of the WEB, so in your case the function chkForm (if it was in the Sandbox web) would be converted to Sandbox.chkForm. My solution was not to use a CamelCase function name, for example chk_form instead of chkForm.

-- MarkRobins - 27 Mar 2007

Interesting: your comment suggest that this may be related to Bugs:Item3813 which I submitted just yesterday. I may add a test case for this to that bug report.

-- LynnwoodBrown - 27 Mar 2007

Mark: I could not duplicate what you observed (see test case in the bug report). Just to note, I copied your format for the function name, although that is not really CamelCase since it does not begin with an upper case. If you did use true CamelCase, then I would expect it to do insert the web reference. However, using the format you have your comment, I can't reproduce your problem. Feel free to comment in the bug topic if you have any additional useful information. Thanks!

-- LynnwoodBrown - 27 Mar 2007

Lynnwood: Yes, you are right of course, the above example is not really CamelCase, but with the issue I had with my function name was indeed CamelCase - hence my problem. I have also added a comment to Bugs:Item3813.

-- MarkRobins - 27 Mar 2007

Change status to:
Edit | Attach | Watch | Print version | History: r14 < r13 < r12 < r11 < r10 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r14 - 2007-03-27 - MarkRobins
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.