Connecting Tech Pros Worldwide Help | Site Map

[Javascript] Hidden fields

 
LinkBack Thread Tools Search this Thread
  #1  
Old September 1st, 2008, 09:13 AM
Familiar Sight
 
Join Date: Oct 2007
Posts: 226
Default [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 ???



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="-;-">
Reply
  #2  
Old September 1st, 2008, 10:16 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,236
Default

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

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?
Reply
  #4  
Old September 1st, 2008, 12:10 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,236
Default

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

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();"> 
Reply
  #6  
Old September 1st, 2008, 01:20 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,236
Default

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

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?
Reply
  #8  
Old September 1st, 2008, 02:21 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,236
Default

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

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?
Reply
  #10  
Old September 1st, 2008, 02:35 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,236
Default

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

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>
Reply
  #12  
Old September 1st, 2008, 03:36 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,236
Default

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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

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 220,840 network members.