473,385 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[Javascript] Hidden fields

263 100+
[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="-;-">
Sep 1 '08 #1
11 3068
acoder
16,027 Expert Mod 8TB
For a multiple select element, you need to loop over the options and check which ones are selected.
Sep 1 '08 #2
viki1967
263 100+
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?
Sep 1 '08 #3
acoder
16,027 Expert Mod 8TB
All you've done is constructed a string without setting it to anything.
Sep 1 '08 #4
viki1967
263 100+
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();"> 
Sep 1 '08 #5
acoder
16,027 Expert Mod 8TB
Try:
Expand|Select|Wrap|Line Numbers
  1. window.opener.document.FORM1.tec.value = s;
Can you see where you were going wrong?
Sep 1 '08 #6
viki1967
263 100+
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?
Sep 1 '08 #7
acoder
16,027 Expert Mod 8TB
The function is expecting a list/select object, not a string, so pass in one select reference.
Sep 1 '08 #8
viki1967
263 100+
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?
Sep 1 '08 #9
acoder
16,027 Expert Mod 8TB
Pass two lists instead of a string and then loop over both and concatenate the string inside the function.
Sep 1 '08 #10
viki1967
263 100+
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>
Sep 1 '08 #11
acoder
16,027 Expert Mod 8TB
Yep, much better. Glad you got it working.
Sep 1 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gowhera Hussain | last post by:
Use This for Learning Only .... Do Not Try To Act Smart HACKING WITH JAVASCRIPT Dr_aMado Sun, 11 Apr 2004 16:40:13 UTC This tutorial is an overview of how javascript can be used to bypass...
1
by: Ryann | last post by:
I hate javascript looking for help. I am trying to pass hidden fields around without showing a query string in the address bar. e.g. formA.asp not formA.asp?var1=blah&var2=blah I have...
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
2
by: Jeff Voigt | last post by:
I just need a few pointers from a few experts to help me finish this up. In a nutshell I want to return the user to where they left off on a page througout numerous postbacks. So far, and with...
7
by: Lau Lei Cheong | last post by:
Hello, I'm using javascript's insertAdjacentHtml() to insert images to the webform at runtime. This runs fine(image successfully displayed at the browser) but when I tried to access the...
4
by: Ken Nipper | last post by:
Does anyone know how to access the menu items from javascript. I can use the onclick to perform an action but I would like to be enable/disable items based on page status. Thanks Ken
7
by: Andy | last post by:
Hi, I have a complicated question that I'm hoping someone can help me out with. I have a webpage that contains a plug-in. This plug-in can communicate/pass data with the webpage that contains it...
4
by: Shawn Repphan | last post by:
I apoligize if this is out of scope with this group. I have a textbox that displays a current record number(xx of xxx). The user has the ability to enter their own number into this box and perform...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
6
by: john | last post by:
I have the following textbox setup with Text & ToolTip Bindings as follows; I'm using Visual Studio 2008 VB: <asp:TextBox ID="txtDay1" runat="server" Text='<%# Eval("Day1") %>'...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.