JavaScript - presupuesto javascript

 
Vista:
sin imagen de perfil

presupuesto javascript

Publicado por luccos (1 intervención) el 27/09/2016 17:13:47
Hola buenas, soy nuevo y tengo una duda y querría saber la opinión de gente más preparada que yo, gracias por anticipado.

La duda es:
cuando selecciono el tipo de página, me marca el precio marcado, y marco casillas me va sumando el precio y restando según marco, hasta ahí bien, pero cuando selecciono otro tipo de página ya está el lío porque me lo suma a lo que tenía antes y no me lo resta o lo suma según la selección que haga.(Quiero que hacer lo mismo que con el check según marque incremente o disminuya el precio)

Se que incluso la duda está mal explicada y pido perdón por anticipado. Gracias.




<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
<script>
function suma(obj){
total=parseInt(document.getElementById("precio").value.replace(",",""));
if(obj.checked){
total+=parseInt(obj.value);
}else{
total-=parseInt(obj.value);
}
txttotal=total+"";
if (txttotal=="0") txttotal="";
document.getElementById("precio").value=txttotal.substring(0,txttotal.length-0)+","+txttotal.substring(txttotal.length-0);
}
</script>
</head>

<body>
<input type="checkbox" name="1" value="50" onChange="suma(this)" /> Quienes somos &nbsp;

<input type="checkbox" name="2" value="50" onChange="suma(this)"/> Donde estamos &nbsp;

<input type="checkbox" name="3" value="50" onChange="suma(this)"/> Galería de fotos &nbsp;

<input type="checkbox" name="4" value="50" onChange="suma(this)"/> e-Commerce &nbsp;<br /><br />

<input type="checkbox" name="5" value="50" onChange="suma(this)"/> Gestión interna &nbsp;

<input type="checkbox" name="6" value="50" onChange="suma(this)"/> Noticias &nbsp;

<input type="checkbox" name="7" value="50" onChange="suma(this)"/> Facebook &nbsp;

<input type="checkbox" name="8" value="50" onChange="suma(this)" /> Twitter &nbsp;<br /><br /><br />



SELECCIONA TIPO DE PAGINA:
<select name="precio" onchange="suma(this)">
<option value="" selected></option>
<option name="9" value="-300" onChange="suma(this)">Comercio</option>
<option name="10" value="-350" onChange="suma(this)">Restaurantes y bares</option>
<option name="11" value="-475" onChange="suma(this)">Gestorias</option>
<option name="12" value="-350" onChange="suma(this)">Automovilismo</option>
</select><br><br />

Presupuesto estimado:<br />
<input type="text" name="total" id="precio" value="0" /> &nbsp;€
</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

solucion?

Publicado por francisco javier (1 intervención) el 04/11/2021 23:17:14
hola buenas, llegaste a encontrar la solucion?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

presupuesto javascript [Solución]

Publicado por grayTurtle01 (1 intervención) el 05/11/2021 02:56:02
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Documento sin título</title>
<script>
 
  // initial values
  total = 0
  total_check = 0
  total_select = 0
 
  document.querySelector("precio").value = total
 
  function suma(obj){
 
    // Checkboxes
    if( obj.type == 'checkbox'){
      if(obj.checked){
        total_check += parseInt(obj.value);
      }else{
        total_check -= parseInt(obj.value);
      }
    }
 
    // Selector
    if( obj.type == 'select-one'){
      total -= total_select
      total_select = parseInt(obj.value)
    }
 
    // Total
    total = total_check + total_select
 
    precio = document.getElementById("precio")
    precio.value = total
 
  }
</script>
</head>
 
<body>
  <input type="checkbox" name="1" value="50" onChange="suma(this)" /> Quienes somos &nbsp;
  <input type="checkbox" name="2" value="50" onChange="suma(this)"/> Donde estamos &nbsp;
  <input type="checkbox" name="3" value="50" onChange="suma(this)"/> Galería de fotos &nbsp;
  <input type="checkbox" name="4" value="50" onChange="suma(this)"/> e-Commerce &nbsp;<br /><br />
  <input type="checkbox" name="5" value="50" onChange="suma(this)"/> Gestión interna &nbsp;
  <input type="checkbox" name="6" value="50" onChange="suma(this)"/> Noticias &nbsp;
  <input type="checkbox" name="7" value="50" onChange="suma(this)"/> Facebook &nbsp;
  <input type="checkbox" name="8" value="50" onChange="suma(this)" /> Twitter &nbsp;<br /><br /><br />
 
Quiza esto te puede servir.='/img/emoticons/up.gif' width='22' height='22' border='0' />
 
  SELECCIONA TIPO DE PAGINA:
  <select name="precio" onchange="suma(this)">
    <option value="" selected disabled>Tipo de Pagina</option>
    <option name="9" value="300" onChange="suma(this)">Comercio</option>
    <option name="10" value="350" onChange="suma(this)">Restaurantes y bares</option>
    <option name="11" value="475" onChange="suma(this)">Gestorias</option>
    <option name="12" value="350" onChange="suma(this)">Automovilismo</option>
  </select><br><br />
 
  Presupuesto estimado:<br />
  <input type="text" name="total" id="precio" value="0" readonly /> &nbsp;€
</body>
</html>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar