 | 
September 1st, 2008, 10:13 AM
| | Familiar Sight | | Join Date: Oct 2007
Posts: 212
| | [Javascript] Hidden fields
[Javascript] Hidden field
Hello my friends.
This is a htm page that contains a form open in window popUp ( page daughter ).
This form insert a value in the one hidden field called "tec", in other form open in the page mother.
As you can see the select contains multiple attribute.
The problem is that by selecting more names from select tec form page daughter, in the hidden field called "tec" form page mother I have only the first name, for example:
I select value gabriele and giuseppe form page daughter, in the hidden field called "tec" form page mother I have only gabriele.
Why?
Can you help me ??? - <script language="Javascript">
-
-
<!--
-
-
function insertf1(f1) {
-
-
if ( FORM1.tec.value.length > 0 && FORM1.opr.value.length > 0 ) {
-
window.opener.document.FORM1.tec.value=f1;
-
alert("Dati correttamente salvati.");
-
window.close();
-
-
} else {
-
-
alert("Dati obbligatori.");
-
FORM1.tec.focus();
-
-
}
-
-
}
-
-
// -->
-
</script>
-
</head>
-
-
<body>
-
-
<form name="FORM1">
-
-
<select size="15" name="tec" multiple>
-
-
<option>Seleziona</option>
-
<option value="GABRIELE">GABRIELE</option>
-
<option value="GIUSEPPE">GIUSEPPE</option>
-
<option value="DOMENICO">DOMENICO</option>
-
-
</select>
-
-
-
<select size="15" name="opr" multiple>
-
<option>Seleziona</option>
-
<option value="GIOVANNI">GIOVANNI/option>
-
<option value="GIACOMO">GIACOMO</option>
-
<option value="DOROTEO">DOROTEO</option>
-
-
</select>
-
-
-
<a href="javascript:insertf1(document.FORM1.tec.value+';'+document.FORM1.opr.value);">
-
<img border="0" src="salva.gif" width="84" height="16">
This is the hidden field called "tec" form page mother: - <INPUT TYPE="hidden" NAME="tec" VALUE="-;-">
| 
September 1st, 2008, 11:16 AM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
For a multiple select element, you need to loop over the options and check which ones are selected.
| 
September 1st, 2008, 12:33 PM
| | Familiar Sight | | Join Date: Oct 2007
Posts: 212
| | Quote: |
Originally Posted by acoder For a multiple select element, you need to loop over the options and check which ones are selected. | Hi acoder, thanks x your reply.
I write this for your suggestion: - function options_value_selezionati_join(lista)
-
{
-
var s = "";
-
for(var i = 0; i < lista.options.length; i++)
-
-
{
-
if(lista.options[i].selected) s += "-" + lista.options[i].value;
-
-
}
-
-
return s.substr(1);
-
-
}
-
-
...
-
-
<a href="javascript:(options_value_selezionati_join(document.FORM1.tec)+';'+options_value_selezionati_join(document.FORM1.opr));">
The values of select it's correct.... but not open alert "OK" and not close window popup and not insert a value in the hidden field called "tec" in form open in the page mother.
.... :(
Can you help me?
| 
September 1st, 2008, 01:10 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
All you've done is constructed a string without setting it to anything.
| 
September 1st, 2008, 01:23 PM
| | Familiar Sight | | Join Date: Oct 2007
Posts: 212
| | Quote: |
Originally Posted by acoder All you've done is constructed a string without setting it to anything. | Not working... - function options_value_selezionati_join(lista)
-
{
-
-
var s = "";
-
for(var i = 0; i < lista.options.length; i++)
-
-
{
-
-
if(lista.options[i].selected) s += "-" + lista.options[i].value;
-
-
-
-
-
}
-
-
window.opener.document.options_value_selezionati_join(document.FORM1.tec)=lista;
-
-
-
-
-
}
-
-
...
-
-
<a href="javascript:options_value_selezionati_join(document.FORM1.tec); window.close();">
| 
September 1st, 2008, 02:20 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
Try: - window.opener.document.FORM1.tec.value = s;
Can you see where you were going wrong?
| 
September 1st, 2008, 02:28 PM
| | Familiar Sight | | Join Date: Oct 2007
Posts: 212
| | Quote: |
Originally Posted by acoder Try: - window.opener.document.FORM1.tec.value = s;
Can you see where you were going wrong? | - function options_value_selezionati_join(lista)
-
{
-
-
var s = "";
-
for(var i = 0; i < lista.options.length; i++)
-
-
{
-
-
if(lista.options[i].selected) s += "-" + lista.options[i].value;
-
-
}
-
window.opener.document.FORM1.tec.value = s;
-
alert("OK.");
-
window.close();
-
-
-
-
}
thanks, working but: -
-
-
<a href="javascript:options_value_selezionati_join(document.FORM1.tec+';'+document.FORM1.opr);">
-
-
Response whit 'options.lengh' is null or not object... why?
| 
September 1st, 2008, 03:21 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
The function is expecting a list/select object, not a string, so pass in one select reference.
| 
September 1st, 2008, 03:27 PM
| | Familiar Sight | | Join Date: Oct 2007
Posts: 212
| | Quote: |
Originally Posted by acoder The function is expecting a list/select object, not a string, so pass in one select reference. | I need pass this string:
<a href="javascript :options_value_selezionati_join(do cument.FORM1.tec+';'+document.FORM1.opr)">
Any idea?
| 
September 1st, 2008, 03:35 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
Pass two lists instead of a string and then loop over both and concatenate the string inside the function.
| 
September 1st, 2008, 04:11 PM
| | Familiar Sight | | Join Date: Oct 2007
Posts: 212
| | Quote: |
Originally Posted by acoder Pass two lists instead of a string and then loop over both and concatenate the string inside the function. | thanks now working, this is solution: - <script language="Javascript">
-
-
<!--
-
-
function options_value_selezionati_join(lista)
-
{
-
var s = "";
-
for(var i = 0; i < lista.options.length; i++)
-
{
-
if(lista.options[i].selected) s += "," + lista.options[i].value;
-
}
-
return s.substr(1);
-
}
-
-
-
function go()
-
{
-
var s1 = options_value_selezionati_join(document.FORM1.tec)
-
var s2 = options_value_selezionati_join(document.FORM1.opr);
-
-
if(s1 == "" || s2 == "")
-
{
-
alert("Stop!");
-
return;
-
}
-
-
var s = s1 + ";" + s2;
-
-
if(window.opener && window.opener.document.FORM1.tec) window.opener.document.FORM1.tec.value = s;
-
alert("OK.");
-
window.close();
-
}
-
-
-
// -->
-
</script>
-
-
...
-
-
<a href="#" onclick="go();return false;">
-
<img border="0" src="save.gif" width="84" height="16"></a>
| 
September 1st, 2008, 04:36 PM
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 12,964
| |
Yep, much better. Glad you got it working.
|  | | Thread Tools | Search this Thread | | | |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | What is Bytes?
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 205,248 network members.
|