0

The question emerges from the discussion with Christoph in my last question 'HTML: target=”_blank” for a drop-down list' and the alternative method by Andrew.

Problem: to run code server-side because some users lack Javascript support. The situation is a form like here.

Some suggestions:

Christoph's recommendation:

<form action="path-to-redirection-script" method="GET" target="_blank"
 onsubmit="window.open(this.elements['foo'].value); return false;">
 <select name="foo" size="1">
  <option value="http://google.com">google</option>
 </select>
 <input type="submit" value="go">
</form>

Alternative method by Andrew:

<form onsubmit="this.js_enabled.value=1;return true;">
    <input type="hidden" name="js_enabled" value="0">
    <input type="submit" value="go">
</form>

Question: How would you do the server-side scripting in the case of form?

5
  • Gab Royer: I will outline the suggestions. C's method relies totally on the server, fetching the script each time from the server. In contrast, A's method fetch the code only from the server if the user has no JS support. Otherwise, client runs the JS. Commented Jul 13, 2009 at 23:29
  • 2
    What kind of scripting languages are you permitted to use on your server? Commented Jul 13, 2009 at 23:35
  • Sorry SimpleThings I deleted my comment because I was a bit ashamed not to understand the question as it didn't seem that hard for other people... But thanks a lot for sorting it out! Commented Jul 14, 2009 at 0:00
  • heh gab, took me about three minutes to figure it out :) Commented Jul 14, 2009 at 0:21
  • 1
    @SimpleThings: the server-side script only gets calles if scripting is disabled: see my answer for details Commented Jul 14, 2009 at 9:07

2 Answers 2

2

Actually, it depends on the server-side language you're going to use.

But, it's as simple as reading out the values in the POST and GET Values the Form delivers you.

i.e. PHP:

if($_POST["js_enabled"] == 0)  
{  
   doSomething(); // Redirecting   
}

But don't forget to validate all values.

good luck,
rAyt

Edit

There you go (pretty good answer though)

How are POST and GET variables handled in Python?

Sign up to request clarification or add additional context in comments.

4 Comments

a small problem, my admin does not allow PHP. (Please, do not remove your answer. It may be useful to others with PHP support.)
What server-side scripting options does your admin allow?
barrowc: cwrea: zsh, python and lua.
I would recommend you python. kinda strange though that php isn't allowed :)
1

There's no need for any additional code or checking for scripting on the server side: Because of the return false in the onsubmit handler, the form won't be submitted if the handler is executed!

Returning false from event handlers supresses the default action associated with the event the same way as calling event.preventDefault() (event.returnValue = false in IE) does.

8 Comments

Situation: onsubmit="window.open(this.elements['foo'].value); return false;"
If JS support, it opens a Window and return false so the server must process the code.
But it is the same with JS support. I probably misunderstood something.
@SimpleThings: if JS is enabled, the return false will suppress the default action, ie the form won't be submitted, ie the server-side script won't be called
Situation: <form action="path-to-redirection-script" method="GET" target="_blank" onsubmit="window.open(this.elements['foo'].value); return false;">
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.