By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,963 Members | 1,815 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,963 IT Pros & Developers. It's quick & easy.

Strange problem

P: n/a
Consider the form below. When I press "Concedi" button all parameters are
correctly sent to the destination page apart from "scadenza" that is sent as
"undefined". Can you give me an explanation of this?

<form name="operazioni_extra">
<table class="leghe_private">
<tr><td class="intestazione">[Nome lega]</td></tr>
<tr><td class="contenitore_invita_utente">
<table><tr><td class="subintestazione">Concedi operazioni extra</td></tr>
<tr><td class="regola_regolamento">Quante operazioni?&nbsp;<input
type="text" name="operazioni" size="3"><br>
Scadenza:<br><input type="radio" name="scadenza" value="indefinita">nessuna
scadenza.<br>
<input type="radio" name="scadenza" value="definita">tra <input type="text"
name="scad_giorni" size="3"> giorni.</td></tr>
<tr><td class="bottoni">
<input type="button" value="Annulla"
onClick="document.location.href='pannello_di_contr ollo.php?lega=[Nome
lega]&aspetto=extra'">
&nbsp;&nbsp;
<input type="button" value="Concedi"
onClick="document.location.href='pannello_di_contr ollo.php?lega=[Nome
lega]&aspetto=operazioni_extra_concesse&operazioni='+do cument.operazioni_extra.operazioni.value+'&scadenz a='+document.operazioni_extra.scadenza.value+'&sca d_giorni='+document.operazioni_extra.scad_giorni.v alue">
</td></tr></table></td></tr></table>
</form>

Thank you in advance for your support.

Cordially,
Mirco Soderi
Dec 20 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Mirco Soderi wrote:
Consider the form below. When I press "Concedi" button all parameters are
correctly sent to the destination page apart from "scadenza" that is sent as
"undefined". Can you give me an explanation of this?
perhaps
<form name="operazioni_extra">
name is deprecated - I believe that applies to forms as well. Use 'id'
instead.

Where is the rest of your declaration? (action, type?)
<input type="button" value="Concedi"
onClick="document.location.href='pannello_di_contr ollo.php?lega=[Nome
lega]&aspetto=operazioni_extra_concesse&operazioni='
+document.operazioni_extra.operazioni.value+'&scad enza='
+document.operazioni_extra.scadenza.value+'&scad_g iorni='
+document.operazioni_extra.scad_giorni.value">


Why are you using onclick here instead of putting
action='pannello_di_controllo.php' in your <form> tag?

There is no need for onclick that I can see - you would be better off
defining the form according to normal conventions.

Also - remember that you won't get a defined value if neither scadenza
option is selected - you may want to consider defining one as the
default selection.

Dec 20 '05 #2

P: n/a
On 20/12/2005 17:02, Mirco Soderi wrote:
Consider the form below.
Did that. Now I must wonder why on Earth you aren't submitting it with
two submit buttons. Instead of checking the 'aspetto' value for 'extra'
or 'operazioni_extra_concesse', name both buttons 'aspetto' and check
for 'Annulla' or 'Concedi', respectively[1].
When I press "Concedi" button all parameters are correctly sent to
the destination page apart from "scadenza" that is sent as
"undefined". Can you give me an explanation of this?


You have two controls named 'scadenza', so:

document.forms.operazioni_extra.elements.scadenza

evaluates to a collection (similar to an array) that references both
controls. This collection doesn't have a value property, so you quite
rightly obtain an undefined value.

What you need to do is determine which is selected and return the value
of that control:

function getCheckedValue(group, form) {
if('string' == typeof group) {
group = form.elements[group];
}
for(var i = 0, n = group.length; i < n; ++i) {
if(group[i].checked) {
return group[i].value;
}
}
}
getCheckedValue('scadenza', document.forms.operazioni_extra);

[snip]

If you post code in future, please present it nicely, and manually
wrapped to less than 75 characters.

Mike
[1] If IE wasn't so broken, you could use a BUTTON element
instead and avoid changing the server-side script.

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Dec 20 '05 #3

P: n/a
Tony wrote:
Mirco Soderi wrote:
Consider the form below. When I press "Concedi" button all parameters are
correctly sent to the destination page apart from "scadenza" that is sent
as "undefined". Can you give me an explanation of this?
perhaps
<form name="operazioni_extra">


name is deprecated -


It is not.
I believe that applies to forms as well.
It does not.
Use 'id' instead.
There is no identifying attribute necessary here whatsoever, neither `id'
nor `name'. However, the `action' attribute is #REQUIRED for the `form'
element.
Where is the rest of your declaration? (action, type?)
<input type="button" value="Concedi"
onClick="document.location.href='pannello_di_contr ollo.php?lega=[Nome
lega]&aspetto=operazioni_extra_concesse&operazioni='
+document.operazioni_extra.operazioni.value+'&scad enza='
+document.operazioni_extra.scadenza.value+'&scad_g iorni='
+document.operazioni_extra.scad_giorni.value">

If scripting were required (which it is not, see below),

function submitData(b)
{
var f, el;
if (b && (f = b.form) && (el = f.elements))
{
var
dummy = function(x) { return x; },
esc = (typeof encodeURIComponent == "function"
? encodeURIComponent
: (typeof escape == "function" ? escape : dummy));

window.location =
'pannello_di_controllo.php?lega=%5bNome lega%5d'
+ '&aspetto=operazioni_extra_concesse'
+ '&operazioni=' + esc(el['operazioni'].value)
+ '&scadenza=' + esc(el['scadenza'].value)
+ '&scad_giorni=' + esc(el['scad_giorni'].value);
}

return false;
}

document.write(
'<input type="button" value="Concedi"'
+ ' onclick="return submitData(this);">');

would suffice. Note that some characters are not allowed unescaped in URIs,
see RFC3986.
Why are you using onclick here instead of putting
action='pannello_di_controllo.php' in your <form> tag?

There is no need for onclick that I can see - you would be better off
defining the form according to normal conventions.


Exactly, the OP is most certainly looking for <input type="submit" ...>
PointedEars
Dec 20 '05 #4

P: n/a
Michael Winter wrote:
If you post code in future, please present it nicely,
and manually wrapped to less than 75 characters.


I am OK with up to 76 characters.
PointedEars
Dec 20 '05 #5

P: n/a
Thomas 'PointedEars' Lahn said the following on 12/20/2005 2:51 PM:
Michael Winter wrote:

If you post code in future, please present it nicely,
and manually wrapped to less than 75 characters.

I am OK with up to 76 characters.


All stop the world!!! Thomas has proclaimed that 76 characters is fine
as opposed to 75.

You are in my sites boy.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Dec 20 '05 #6

P: n/a
Randy Webb wrote:
[...]
You are in my sites ...

That's gotta be the worst web pun I've seen in quite a while. :-p


--
Rob
Dec 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.