JavaScript - Agregar y quitar valor de CheckBox en IFRAME

 
Vista:
sin imagen de perfil

Agregar y quitar valor de CheckBox en IFRAME

Publicado por Nelson (1 intervención) el 02/05/2014 18:10:43
Hola, saludos a todos los usuarios que vieron este mensaje.

tengo un pequeño problema con una funcion en javascript que quiero resolver y de tanto buscar no encontre forma de hacerlo o guiarme.

Tengo 2 checkbox y un iframe... al chequear la casilla me aparece el valor en el iframe y cuando desmarco se borra
pero el problema existe cuando selecciono ambas casillas ya que necesito que si el usuario desmarca alguna de las opciones solo se borre el valor de la casilla desmarcada y en este ejemplo se borran ambos y no es lo q necesito

el ejemplo del que me guíe lo hicieron a traves de un textarea y funciona bien solo borra el valor desmarcado

sera que me pueden ayudar a resolver mi pequeño problema?

la funcion para agregar y quitar es agregar_columna
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script>
function submit_form(){
 
	var theForm = document.getElementById("myform");
	theForm.elements["myTextArea"].value = window.frames['richTextField'].document.body.innerHTML;
	theForm.submit();
 
 
 
 
}
     function agregar_columna(chexbox){
        if  (chexbox.checked){
           window.frames['richTextField'].document.body.innerHTML += chexbox.value = ((chexbox.value != '')? ' ':' ')+chexbox.value;
 
			//window.frames['richTextField'].document.body.innerHTML = chexbox.value;
        }
        else{
 
 
		 window.frames['richTextField'].document.body.innerHTML = chexbox.value.replace( new  RegExp(chexbox.value,"g" ),''). replace( /^,*/ ,'');
 
 
        }
      }
 
</script>
</head>
 
<body>
<form action="report_constancia.php" name="myform" id="myform" method="post">
<input type="checkbox" value="Fecha" name="chex[]" onChange="agregar_columna(this)"/>
<input type="checkbox" value="chag" name="chex[]" onChange="agregar_columna(this)"/>
<br/>
<textarea style="display:none;" name="myTextArea" id="myTextArea" cols="100" rows="14" vale=""></textarea>
<iframe name="richTextField" id="richTextField" style="border:#000000 1px solid; width:700px; height:300px;"></iframe>
<br/>
<input name="myBton" type="button" value="Submid Data" onClick="javascript:submit_form();">
</form>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder