Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 1st, 2008, 10:13 AM
Familiar Sight
 
Join Date: Oct 2007
Posts: 212
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 ???



Code:
<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:

Code:
<INPUT TYPE="hidden" NAME="tec" VALUE="-;-">
Reply
  #2  
Old September 1st, 2008, 11:16 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
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, 12:33 PM
Familiar Sight
 
Join Date: Oct 2007
Posts: 212
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:

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

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

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

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

Try:
[code=javascript]window.opener.document.FORM1.tec.value = s;[/code]Can you see where you were going wrong?
Reply
  #7  
Old September 1st, 2008, 02:28 PM
Familiar Sight
 
Join Date: Oct 2007
Posts: 212
Default

Quote:
Originally Posted by acoder
Try:
[code=javascript]window.opener.document.FORM1.tec.value = s;[/code]Can you see where you were going wrong?
Code:
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:


Code:
 

<a href="javascript:options_value_selezionati_join(document.FORM1.tec+';'+document.FORM1.opr);">
Response whit 'options.lengh' is null or not object... why?
Reply
  #8  
Old September 1st, 2008, 03:21 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

The function is expecting a list/select object, not a string, so pass in one select reference.
Reply
  #9  
Old September 1st, 2008, 03:27 PM
Familiar Sight
 
Join Date: Oct 2007
Posts: 212
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, 03:35 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
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, 04:11 PM
Familiar Sight
 
Join Date: Oct 2007
Posts: 212
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:

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

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

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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 network members.
Post your question now . . .
It's fast and it's free

Popular Articles