Connecting Tech Pros Worldwide Help | Site Map

[Javascript] Hidden fields

  #1  
Old September 1st, 2008, 10:13 AM
Familiar Sight
 
Join Date: Oct 2007
Posts: 250
[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 ???



Expand|Select|Wrap|Line Numbers
  1. <script language="Javascript">
  2.  
  3. <!--
  4.  
  5. function insertf1(f1) {
  6.  
  7.    if ( FORM1.tec.value.length > 0 && FORM1.opr.value.length > 0 ) {
  8.         window.opener.document.FORM1.tec.value=f1;
  9.         alert("Dati correttamente salvati.");
  10.         window.close();
  11.  
  12.     } else {
  13.  
  14.         alert("Dati obbligatori."); 
  15.         FORM1.tec.focus(); 
  16.  
  17.    }
  18.  
  19. }
  20.  
  21. // -->
  22. </script>
  23. </head>
  24.  
  25. <body>
  26.  
  27. <form name="FORM1">
  28.  
  29. <select size="15" name="tec" multiple>
  30.  
  31. <option>Seleziona</option>
  32. <option value="GABRIELE">GABRIELE</option>                   
  33. <option value="GIUSEPPE">GIUSEPPE</option>
  34. <option value="DOMENICO">DOMENICO</option>
  35.  
  36. </select> 
  37.  
  38.  
  39. <select size="15" name="opr" multiple>
  40. <option>Seleziona</option>
  41. <option value="GIOVANNI">GIOVANNI/option>                   
  42. <option value="GIACOMO">GIACOMO</option>
  43. <option value="DOROTEO">DOROTEO</option>
  44.  
  45. </select>
  46.  
  47.  
  48. <a href="javascript:insertf1(document.FORM1.tec.value+';'+document.FORM1.opr.value);">            
  49. <img border="0" src="salva.gif" width="84" height="16"> 
This is the hidden field called "tec" form page mother:

Expand|Select|Wrap|Line Numbers
  1. <INPUT TYPE="hidden" NAME="tec" VALUE="-;-">
  #2  
Old September 1st, 2008, 11:16 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

re: [Javascript] Hidden fields


For a multiple select element, you need to loop over the options and check which ones are selected.
  #3  
Old September 1st, 2008, 12:33 PM
Familiar Sight
 
Join Date: Oct 2007
Posts: 250

re: [Javascript] Hidden fields


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:

Expand|Select|Wrap|Line Numbers
  1.     function options_value_selezionati_join(lista)
  2.     {
  3.         var s = "";
  4.         for(var i = 0; i < lista.options.length; i++)
  5.  
  6.         {
  7.             if(lista.options[i].selected) s += "-" + lista.options[i].value;  
  8.  
  9.         }
  10.  
  11.         return s.substr(1);
  12.  
  13.    }
  14.  
  15. ...
  16.  
  17.             <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?
  #4  
Old September 1st, 2008, 01:10 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

re: [Javascript] Hidden fields


All you've done is constructed a string without setting it to anything.
  #5  
Old September 1st, 2008, 01:23 PM
Familiar Sight
 
Join Date: Oct 2007
Posts: 250

re: [Javascript] Hidden fields


Quote:
Originally Posted by acoder
All you've done is constructed a string without setting it to anything.
Not working...

Expand|Select|Wrap|Line Numbers
  1. function options_value_selezionati_join(lista)
  2.     {
  3.  
  4.         var s = "";
  5.         for(var i = 0; i < lista.options.length; i++)
  6.  
  7.         {
  8.  
  9.             if(lista.options[i].selected) s += "-" + lista.options[i].value; 
  10.  
  11.  
  12.  
  13.  
  14.         }        
  15.  
  16.                 window.opener.document.options_value_selezionati_join(document.FORM1.tec)=lista;
  17.  
  18.  
  19.  
  20.  
  21.    }
  22.  
  23. ...
  24.  
  25. <a href="javascript:options_value_selezionati_join(document.FORM1.tec); window.close();"> 
  #6  
Old September 1st, 2008, 02:20 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

re: [Javascript] Hidden fields


Try:
Expand|Select|Wrap|Line Numbers
  1. window.opener.document.FORM1.tec.value = s;
Can you see where you were going wrong?
  #7  
Old September 1st, 2008, 02:28 PM
Familiar Sight
 
Join Date: Oct 2007
Posts: 250

re: [Javascript] Hidden fields


Quote:
Originally Posted by acoder
Try:
Expand|Select|Wrap|Line Numbers
  1. window.opener.document.FORM1.tec.value = s;
Can you see where you were going wrong?
Expand|Select|Wrap|Line Numbers
  1. function options_value_selezionati_join(lista)
  2.     {
  3.  
  4.         var s = "";
  5.         for(var i = 0; i < lista.options.length; i++)
  6.  
  7.         {
  8.  
  9.             if(lista.options[i].selected) s += "-" + lista.options[i].value;
  10.  
  11.           }                 
  12.                 window.opener.document.FORM1.tec.value = s;   
  13.                 alert("OK.");
  14.                 window.close();  
  15.  
  16.  
  17.  
  18.    }
thanks, working but:


Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <a href="javascript:options_value_selezionati_join(document.FORM1.tec+';'+document.FORM1.opr);">
  4.  
  5.  
Response whit 'options.lengh' is null or not object... why?
  #8  
Old September 1st, 2008, 03:21 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

re: [Javascript] Hidden fields


The function is expecting a list/select object, not a string, so pass in one select reference.
  #9  
Old September 1st, 2008, 03:27 PM
Familiar Sight
 
Join Date: Oct 2007
Posts: 250

re: [Javascript] Hidden fields


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?
  #10  
Old September 1st, 2008, 03:35 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

re: [Javascript] Hidden fields


Pass two lists instead of a string and then loop over both and concatenate the string inside the function.
  #11  
Old September 1st, 2008, 04:11 PM
Familiar Sight
 
Join Date: Oct 2007
Posts: 250

re: [Javascript] Hidden fields


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:

Expand|Select|Wrap|Line Numbers
  1. <script language="Javascript">
  2.  
  3. <!--
  4.  
  5.     function options_value_selezionati_join(lista)
  6.     {
  7.         var s = "";
  8.         for(var i = 0; i < lista.options.length; i++)
  9.         {
  10.             if(lista.options[i].selected) s += "," + lista.options[i].value;
  11.         }
  12.         return s.substr(1);
  13.     }
  14.  
  15.  
  16. function go()
  17. {
  18.     var s1 = options_value_selezionati_join(document.FORM1.tec)
  19.     var s2 = options_value_selezionati_join(document.FORM1.opr);
  20.  
  21.     if(s1 == "" || s2 == "")
  22.     {
  23.         alert("Stop!");
  24.         return;
  25.     }
  26.  
  27.     var s = s1 + ";" + s2;
  28.  
  29.     if(window.opener && window.opener.document.FORM1.tec) window.opener.document.FORM1.tec.value = s;  
  30.     alert("OK."); 
  31.     window.close();
  32. }    
  33.  
  34.  
  35. // -->
  36. </script>
  37.  
  38. ...
  39.  
  40. <a href="#" onclick="go();return false;">
  41.             <img border="0" src="save.gif" width="84" height="16"></a>
  #12  
Old September 1st, 2008, 04:36 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,526
Provided Answers: 12

re: [Javascript] Hidden fields


Yep, much better. Glad you got it working.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Python CGI: Hidden fields don't show up in submitted keys! BcNexus answers 0 May 8th, 2006 07:45 AM
Moving to 4.01 strict: problem with hidden fields et al. Mark McLellan answers 10 July 24th, 2005 12:14 AM
Form submit w/ hidden fields using text only sams@centric.net answers 5 July 23rd, 2005 06:48 PM
Add hidden fields to form onSubmit Sam Wuebben answers 1 July 23rd, 2005 01:53 PM