[Javascript] Checkbox values | Member | | Join Date: Apr 2008
Posts: 66
| |
[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:
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:
response with: - undefined;undefined;undefined;undefined
Can you help me?
kind regards
mike
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: [Javascript] Checkbox values
Can you explain what you mean by "checkbox returned by the query SQL is unique/different"?
| | Member | | Join Date: Apr 2008
Posts: 66
| | | re: [Javascript] Checkbox values 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: - <input type="checkbox" name="DETTAGLIO_1" value="CS7">
checkbox different in the secondary form: -
-
<input type="checkbox" name="DETTAGLIO_1" value="CS7">
-
-
<input type="checkbox" name="DETTAGLIO_2" value="CS20">
-
-
<input type="checkbox" name="DETTAGLIO_3" value="NCS24">
-
-
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: [Javascript] Checkbox values
How do you generate the LG string?
| | Member | | Join Date: Apr 2008
Posts: 66
| | | re: [Javascript] Checkbox values 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
| | Member | | Join Date: Apr 2008
Posts: 66
| | | re: [Javascript] Checkbox values
I have change the code.
This is main form: -
-
<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: |  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: [Javascript] Checkbox values
The problem is line 286: - <a href="javascript:insertf1(document.myform.SOTTODETTAGLIO _VERIFICA_6.value+';'+document.myform.Esito.value+ ';'+document.myform.ITEMS_6.value+';'+document.myf orm.ITEMS_KO_6.value)">
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?
| | Member | | Join Date: Apr 2008
Posts: 66
| | | re: [Javascript] Checkbox values Quote:
Originally Posted by acoder The problem is line 286: - <a href="javascript:insertf1(document.myform.SOTTODETTAGLIO _VERIFICA_6.value+';'+document.myform.Esito.value+ ';'+document.myform.ITEMS_6.value+';'+document.myf orm.ITEMS_KO_6.value)">
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: - <a href="javascript:insertf1(document.myform.SOTTODETTAGLIO _VERIFICA_6.value+';'+document.myform.Esito.value+ ';'+document.myform.ITEMS_6.value+';'+document.myf orm.ITEMS_KO_6.value)">
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.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: [Javascript] Checkbox values
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.
| | Member | | Join Date: Apr 2008
Posts: 66
| | | re: [Javascript] Checkbox values 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?: -
-
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;">
-
-
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: [Javascript] Checkbox values
You're starting from 0 and the IDs start from 1.
| | Member | | Join Date: Apr 2008
Posts: 66
| | | re: [Javascript] Checkbox values Quote:
Originally Posted by acoder You're starting from 0 and the IDs start from 1. Error not change: -
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();
-
-
}
-
-
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: [Javascript] Checkbox values
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.
| | Member | | Join Date: Apr 2008
Posts: 66
| | | re: [Javascript] Checkbox values 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...
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: [Javascript] Checkbox values
Then the 7 should be replaced by a dynamic value generated from the server-side which changes depending on the number of fields.
| | Member | | Join Date: Apr 2008
Posts: 66
| | | re: [Javascript] Checkbox values 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: -
-
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;">
-
-
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: [Javascript] Checkbox values
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.
| | Member | | Join Date: Apr 2008
Posts: 66
| | | re: [Javascript] Checkbox values 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/ |  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: [Javascript] Checkbox values
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.
| | Member | | Join Date: Apr 2008
Posts: 66
| | | re: [Javascript] Checkbox values 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.
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: [Javascript] Checkbox values
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.
| | Member | | Join Date: Apr 2008
Posts: 66
| | | re: [Javascript] Checkbox values 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: -
-
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>
-
|  | Site Moderator | | Join Date: Nov 2006 Location: UK
Posts: 14,581
| | | re: [Javascript] Checkbox values
Oh, so you wanted all the fields in the form?
Anyway, glad to hear that you've managed to solve it.
|  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
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 226,501 network members.
|