Help | Site Map
Connecting Tech Pros Worldwide
Reply
 
LinkBack Thread Tools
  #1  
Old September 3rd, 2008, 04:36 PM
Member
 
Join Date: Apr 2008
Posts: 66
Default [Javascript] Checkbox values

[Javascript] Checkbox values

Hello.

I have a problem with this code ASP / Javascript.

The problem is JavaScript; try this LINK and select value cespiti

1) With ASP language is populated a secondary form, generated by a main form with a series of checkboxes, text fields and select;

2) Selecting different checkbox from a secondary form and compiled other fields, this values must be copied to a single field hidden in the principal form;

If the checkbox returned by the query SQL, is unique, the string:

Code:
 return LG.substr();
is right and compiled values in the field hidden in principal form.

But if the checkbox returned by the query SQL are different, the string:

Code:
 return LG.substr();
response with:

Code:
undefined;undefined;undefined;undefined
Can you help me?

kind regards
mike
Reply
  #2  
Old September 3rd, 2008, 07:11 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

Can you explain what you mean by "checkbox returned by the query SQL is unique/different"?
Reply
  #3  
Old September 3rd, 2008, 07:30 PM
Member
 
Join Date: Apr 2008
Posts: 66
Default

Quote:
Originally Posted by acoder
Can you explain what you mean by "checkbox returned by the query SQL is unique/different"?
checkbox unique in the secondary form:

Code:
<input type="checkbox" name="DETTAGLIO_1" value="CS7">

checkbox different in the secondary form:

Code:
<input type="checkbox" name="DETTAGLIO_1" value="CS7">

<input type="checkbox" name="DETTAGLIO_2" value="CS20">

<input type="checkbox" name="DETTAGLIO_3" value="NCS24">
Reply
  #4  
Old September 3rd, 2008, 08:51 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

How do you generate the LG string?
Reply
  #5  
Old September 4th, 2008, 06:07 AM
Member
 
Join Date: Apr 2008
Posts: 66
Default

Quote:
Originally Posted by acoder
How do you generate the LG string?
Open this link:
http://users1.titanichost.com/MiguelRivero61/

Select "cespiti" value in the main form;

In the popup page I have secondary form;

Select checkbox and the other fields and click in the button "salva".

Generate LG string
Reply
  #6  
Old September 4th, 2008, 10:19 AM
Member
 
Join Date: Apr 2008
Posts: 66
Default

I have change the code.

This is main form:

Code:
<html>
<head>
<script language="javascript" type="text/javascript">
<!--

// Variabile globale contenente l'istanza 'window' del popup corrente
var popup = null;
 
function Forum(fld, tbl, col, w, h)
{
  var pw = Math.floor((screen.width - w) / 2);
  var ph = Math.floor((screen.height - h) / 2);
 
  // Crea il popup solo se non è già stato aperto
  if (!popup || popup.closed) popup = window.open("popup.htm?f=" + fld + "&t=" + tbl + "&c=" + col, "scelte",
                                                  "width=" + w + ",height=" + h + ",top=" + ph + ",left=" + pw);
 
  // Attiva il popup (portalo in primo piano)
  if (popup) popup.focus();
}

//-->
</script>

</head>

<body> 

<form name=myform action="?upload=1" method="POST">

<INPUT TYPE="hidden" NAME="dati_aggiuntivi" VALUE="xxxx">

<select size="1" name="dettaglio_visita" style="font-size: 8 pt; font-family: Verdana" onchange="Forum(this.value, 'tbl_mac_visite_ispettive_dett', 'DETTAGLIO_VERIFICA', 700, 500); this.selectedIndex = 0;">">

<option>Seleziona</option>
<option value="14-Cespiti">Cespiti</option>
</select> 

</form>

</body>
</html>

This is secondary form:

Code:
  
  
<html>
<head>

<title>Popup</title>
<link rel=stylesheet href=/mac/css/applicativi.css>
<link rel=stylesheet href=/mac/css/menu.css>

<script language="javascript" type="text/javascript">
<!--

function insertf1(f1) {
   
        window.opener.document.myform.dati_aggiuntivi.value=f1;
        //alert("Dati aggiuntivi correttamente salvati.");
        //window.close();
        
        return f1.substr();
   
}

//-->
</script>

</head>

<body>
 
<form name="myform">



<p>&nbsp;</p>

<div align="center">
  <table border="0" id="table1">
    
<tr>
   <td class=blub align="center">Sottodettaglio<br>Verifica</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">Eseguita?</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">Esito della verifica</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">Totale items<br>verificati</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">di cui<br>items KO</td>
</tr>   



<tr>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
</tr>   

<tr>
   <td class=blub align="center">CS7</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_1" value="CS7"></td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">

<select size="1" name="Esito">
   <option>Seleziona Esito</option>
   <option value="Sufficiente">Sufficiente</option>
   <option value="Insufficiente">Insufficiente</option>
   <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
   <option value="Dettagliato in verbale">Dettagliato in verbale</option>
</select></td>
<td class=blub align="center">&nbsp;</td>

<td class=blub align="center"><input type="text" name="ITEMS_1" size="5"></td>
<td class=blub align="center">&nbsp;</td>
<td class=blub align="center"><input type="text" name="ITEMS_KO_1" size="5"></td>

</tr>
      


<tr>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
</tr>   

<tr>
   <td class=blub align="center">CS20</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_2" value="CS20"></td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">

<select size="1" name="Esito">
   <option>Seleziona Esito</option>
   <option value="Sufficiente">Sufficiente</option>
   <option value="Insufficiente">Insufficiente</option>
   <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
   <option value="Dettagliato in verbale">Dettagliato in verbale</option>
</select></td>
<td class=blub align="center">&nbsp;</td>

<td class=blub align="center"><input type="text" name="ITEMS_2" size="5"></td>
<td class=blub align="center">&nbsp;</td>
<td class=blub align="center"><input type="text" name="ITEMS_KO_2" size="5"></td>

</tr>
      


<tr>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
</tr>   

<tr>
   <td class=blub align="center">NCS24</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_3" value="NCS24"></td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">

<select size="1" name="Esito">
   <option>Seleziona Esito</option>
   <option value="Sufficiente">Sufficiente</option>
   <option value="Insufficiente">Insufficiente</option>
   <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
   <option value="Dettagliato in verbale">Dettagliato in verbale</option>
</select></td>
<td class=blub align="center">&nbsp;</td>

<td class=blub align="center"><input type="text" name="ITEMS_3" size="5"></td>
<td class=blub align="center">&nbsp;</td>
<td class=blub align="center"><input type="text" name="ITEMS_KO_3" size="5"></td>

</tr>
      


<tr>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
</tr>   

<tr>
   <td class=blub align="center">NCS25</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_4" value="NCS25"></td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">

<select size="1" name="Esito">
   <option>Seleziona Esito</option>
   <option value="Sufficiente">Sufficiente</option>
   <option value="Insufficiente">Insufficiente</option>
   <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
   <option value="Dettagliato in verbale">Dettagliato in verbale</option>
</select></td>
<td class=blub align="center">&nbsp;</td>

<td class=blub align="center"><input type="text" name="ITEMS_4" size="5"></td>
<td class=blub align="center">&nbsp;</td>
<td class=blub align="center"><input type="text" name="ITEMS_KO_4" size="5"></td>

</tr>
      


<tr>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
</tr>   

<tr>
   <td class=blub align="center">CS21</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_5" value="CS21"></td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">

<select size="1" name="Esito">
   <option>Seleziona Esito</option>
   <option value="Sufficiente">Sufficiente</option>
   <option value="Insufficiente">Insufficiente</option>
   <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
   <option value="Dettagliato in verbale">Dettagliato in verbale</option>
</select></td>
<td class=blub align="center">&nbsp;</td>

<td class=blub align="center"><input type="text" name="ITEMS_5" size="5"></td>
<td class=blub align="center">&nbsp;</td>
<td class=blub align="center"><input type="text" name="ITEMS_KO_5" size="5"></td>

</tr>
      


<tr>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
</tr>   

<tr>
   <td class=blub align="center">CS29</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center"><input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_6" value="CS29"></td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">

<select size="1" name="Esito">
   <option>Seleziona Esito</option>
   <option value="Sufficiente">Sufficiente</option>
   <option value="Insufficiente">Insufficiente</option>
   <option value="Sufficiente con osservazioni">Sufficiente con osservazioni</option>
   <option value="Dettagliato in verbale">Dettagliato in verbale</option>
</select></td>
<td class=blub align="center">&nbsp;</td>

<td class=blub align="center"><input type="text" name="ITEMS_6" size="5"></td>
<td class=blub align="center">&nbsp;</td>
<td class=blub align="center"><input type="text" name="ITEMS_KO_6" size="5"></td>

</tr>
      

  
  </td>
    </tr>

<tr>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">

&nbsp;</td>
<td class=blub align="center">&nbsp;</td>

<td class=blub align="center">&nbsp;</td>
<td class=blub align="center">&nbsp;</td>
<td class=blub align="center">&nbsp;</td>

</tr>
      
<tr>
   <td class=blub align="center" colspan="9">
   <div align="center">
     <table border="0" id="table3">
       <tr>
         <td><p align="center">
            <a href="javascript:insertf1(document.myform.SOTTODETTAGLIO_VERIFICA_6.value+';'+document.myform.Esito.value+';'+document.myform.ITEMS_6.value+';'+document.myform.ITEMS_KO_6.value)">
            <img border="0" src="salva_button.gif" width="84" height="16"></a></td>
         <td>&nbsp;</td>
         <td><p align="center"><a href="javascript:void(0);" onclick="window.close()">
             <input type="image"src="chiudi_button.gif" border="0" align="middle" name="I5"></a></td>
       </tr>
     </table>
   </div>
   </td>

</tr>
      
<tr>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">&nbsp;</td>
   <td class=blub align="center">

&nbsp;</td>
<td class=blub align="center">&nbsp;</td>

<td class=blub align="center">&nbsp;</td>
<td class=blub align="center">&nbsp;</td>
<td class=blub align="center">&nbsp;</td>

</tr>
      
  </table>
</div>

</form>
 
</body>
</html>
Reply
  #7  
Old September 4th, 2008, 11:39 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

The problem is line 286:
[code=html]<a href="javascript:insertf1(document.myform.SOTTODET TAGLIO _VERIFICA_6.value+';'+document.myform.Esito.value+ ';'+document.myform.ITEMS_6.value+';'+document.myf orm.ITEMS_KO_6.value)">[/code]What do you actually want to happen? For example, if I select checkbox 1, do you want anything to appear, or do you always want to pass the last row data?
Reply
  #8  
Old September 4th, 2008, 12:32 PM
Member
 
Join Date: Apr 2008
Posts: 66
Default

Quote:
Originally Posted by acoder
The problem is line 286:
[code=html]<a href="javascript:insertf1(document.myform.SOTTODET TAGLIO _VERIFICA_6.value+';'+document.myform.Esito.value+ ';'+document.myform.ITEMS_6.value+';'+document.myf orm.ITEMS_KO_6.value)">[/code]What do you actually want to happen? For example, if I select checkbox 1, do you want anything to appear, or do you always want to pass the last row data?
Ok I understand.

I need insert in the string:

[code=html]<a href="javascript:insertf1(document.myform.SOTTODET TAGLIO _VERIFICA_6.value+';'+document.myform.Esito.value+ ';'+document.myform.ITEMS_6.value+';'+document.myf orm.ITEMS_KO_6.value)">[/code]

all the values selected in the secondary form and insert this string in the hidden field of the main form; whether a value or more values.
Reply
  #9  
Old September 4th, 2008, 01:09 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

Is there a particular reason why the elements are named differently? You can use the same name, just not the same ID. If you have the same name, you can use document.getElementsByName() to get a list/array of elements which you can loop over. Check the checked property of the checkboxes to see if that row is one of the selected ones to pass the values through.
Reply
  #10  
Old September 4th, 2008, 01:15 PM
Member
 
Join Date: Apr 2008
Posts: 66
Default

Quote:
Originally Posted by acoder
Is there a particular reason why the elements are named differently? You can use the same name, just not the same ID. If you have the same name, you can use document.getElementsByName() to get a list/array of elements which you can loop over. Check the checked property of the checkboxes to see if that row is one of the selected ones to pass the values through.

Ok, I try this but response with error 'Object required', why?:


Code:
function insertf1(stringa) 

{

   var s = "";
   for( var i = 0; i < 7; i++)
 
  {
   
      s += "," + document.getElementById('test_'+i).value;
        
   }   
        window.opener.document.myform.dati_aggiuntivi.value=s;
        
        return s.substr();
   
}

<select size="1" id=test_1" name="test_1">
...
</select>

<select size="1" id=test_2" name="test_2">
...
</select>

<select size="1" id=test_3" name="test_3">
...
</select>

<input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_1" value="NCS43">

<input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_2" value="NCS44">

<input type="checkbox" name="SOTTODETTAGLIO_VERIFICA_3" value="NCS28">

<a href="#" onclick="insertf1();return false;">
Reply
  #11  
Old September 4th, 2008, 01:23 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

You're starting from 0 and the IDs start from 1.
Reply
  #12  
Old September 4th, 2008, 01:25 PM
Member
 
Join Date: Apr 2008
Posts: 66
Default

Quote:
Originally Posted by acoder
You're starting from 0 and the IDs start from 1.
Error not change:

Code:
function insertf1(stringa) 
 
{
 
   var s = "";
   for( var i = 1; i < 7; i++)
 
  {
   
      s += "," + document.getElementById('test_'+i).value;
        
   }   
        window.opener.document.myform.dati_aggiuntivi.value = s;
        
        return s.substr();
   
}
Reply
  #13  
Old September 4th, 2008, 01:29 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

You're not passing anything to insertF1, so you can remove stringa.

In the above code, you have only 3 elements while the loop loops till 6.
Reply
  #14  
Old September 4th, 2008, 01:34 PM
Member
 
Join Date: Apr 2008
Posts: 66
Default

Quote:
Originally Posted by acoder
You're not passing anything to insertF1, so you can remove stringa.

In the above code, you have only 3 elements while the loop loops till 6.
Sorry, I don't understand.

I do not know how many fields I will have on the form secondary...
Reply
  #15  
Old September 4th, 2008, 02:23 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

Then the 7 should be replaced by a dynamic value generated from the server-side which changes depending on the number of fields.
Reply
  #16  
Old September 4th, 2008, 02:56 PM
Member
 
Join Date: Apr 2008
Posts: 66
Default

Quote:
Originally Posted by acoder
Then the 7 should be replaced by a dynamic value generated from the server-side which changes depending on the number of fields.

Yes but this is already done:

Code:
function insertf1(stringa) 
 
{
 
   var s = "";
   for( var i = 1; i < 7; i++)
 
  {
   
      s += "," + document.getElementById('test_'+i).value;
        
   }   
        window.opener.document.myform.dati_aggiuntivi.valu  e = s;
        
        return s.substr();
   
}

...

<form name="form">

<% 
  rs.MoveFirst()
  Do While Not rs.EOF    
%>


<input type="checkbox" name="DETTAGLIO" value="<%=rs("DETTAGLIO")%>">

<select size="1" id="test_<%=list%>" name="test_<%=list%>">
...
</select>

<select size="1" id="test_<%=list%>" name="test_<%=list%>">
...
</select>

<select size="1" id="test_<%=list%>" name="test_<%=list%>">
...
</select>
...


<%  
    rs.MoveNext()
  Loop
%>

...

<a href="#" onclick="insertf1();return false;">
Reply
  #17  
Old September 4th, 2008, 03:54 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

I meant on line 6, the 7 should be replaced by a dynamic value.

You have three select elements, but the code loops till 6, so it would be trying to access "test_4", "test_5", "test_6" which don't exist.
Reply
  #18  
Old September 4th, 2008, 04:03 PM
Member
 
Join Date: Apr 2008
Posts: 66
Default

Quote:
Originally Posted by acoder
I meant on line 6, the 7 should be replaced by a dynamic value.

You have three select elements, but the code loops till 6, so it would be trying to access "test_4", "test_5", "test_6" which don't exist.
OK, please acoder try this page htm:

http://users1.titanichost.com/MiguelRivero61/
Reply
  #19  
Old September 4th, 2008, 04:56 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

I don't think you've made any changes since the last time I checked. The code looks and behaves the same.

If you're using unique IDs, use document.getElementById(). If you're using names, use document.getElementsByName(). Alternatively, you could use document.getElementsByTagName("input") and then check the type/name.
Reply
  #20  
Old September 4th, 2008, 05:14 PM
Member
 
Join Date: Apr 2008
Posts: 66
Default

Quote:
Originally Posted by acoder
I don't think you've made any changes since the last time I checked. The code looks and behaves the same.

If you're using unique IDs, use document.getElementById(). If you're using names, use document.getElementsByName(). Alternatively, you could use document.getElementsByTagName("input") and then check the type/name.

Your help is not the help I think
However, thanks.
Reply
  #21  
Old September 4th, 2008, 05:47 PM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

Something lost in translation?

I've seen the link, but the changes that you're showing in this thread are not reflected in the link. Also, the popup page is a .html file while you've shown that you're using ASP.
Reply
  #22  
Old September 5th, 2008, 10:09 AM
Member
 
Join Date: Apr 2008
Posts: 66
Default

Quote:
Originally Posted by acoder
Something lost in translation?

I've seen the link, but the changes that you're showing in this thread are not reflected in the link. Also, the popup page is a .html file while you've shown that you're using ASP.
No problem acoder, problem solved:

Code:
function Re(){

var f=document.getElementById('id_form')
var stringa=''

for(var k=0;k<f.elements.length;k++){
  stringa+=f.elements[k].value+',';
}

  window.opener.document.myform.dati_aggiuntivi.value = stringa
  alert("OK!");
  window.close();

}

...

<form id="id_form" name="myform">

...

<a href="#" onclick="Re();">...</a>
Reply
  #23  
Old September 5th, 2008, 11:40 AM
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 12,593
Default

Oh, so you wanted all the fields in the form?

Anyway, glad to hear that you've managed to solve it.
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