if ($kit.Estrutura.1.Info == 0){
let estrutura = ""
} else if (==1){
let estrutura = "Perfil de Alumínio 2.4m"
} else if (==2){
let estrutura = "Kit Longarinas 4800MM - Estrutura de solo ROMAGNOLE"
} else if (==3){
let estrutura = "Mini Trilho - 100mm (A) x 300mm (C) - Alto (1un)"
}
document.getElementById('kitescolhido').innerHTML = `
kit.Reconhecimento.Nome{kit.Valores.Kwp}kWp - Numero do Kit-{kit.Placas.Quantidade}X {kit.Inversores.Quantidade}X {telhadoesco}
100.00
{kit.Placas}
Inversores: {kit.Estruturas}
Kwh: {kit.Reconhecimento.Numero} {kit.Placas.Quantidade}X {kit.Inversores.Quantidade}X {telhadoesco}
5X Sit
5X Amet
${kit.Valores.Kwp} kWp
... codigo
It looks like you're trying to map the selected roof type from your HTML <select> element to a numerical value and then use that value to determine which structure information to display in your JavaScript code. However, there are a few issues with your current code that are causing problems.
Here's a breakdown of the main issues and how to fix them:
Incorrect Syntax in if Statements
The syntax you're using in your if statements is not valid JavaScript. For example:
javascript
if document.getElementById("tipotelhado") ==
"Telha Colonial (Cerâmica)" = 1
This is not the correct way to compare values or assign variables in JavaScript. Additionally, the comparison operator == is misused here.
Missing value Attributes in <option> Tags
Your <option> tags don't have value attributes, which makes it difficult to map the selected option to a numerical value in your JavaScript code.
Invalid JavaScript Variable Definitions
In your else if statements, you're missing the variable or expression to compare. For example:
javascript
else if (==1){
let estrutura = "Perfil de Alumínio 2.4m"
}
The condition ==1 is incomplete because there's no variable or expression on the left side of the == operator.
To fix these issues, follow the steps below:
Step 1: Add value Attributes to Your <option> Tags
Modify your HTML <select> element to include value attributes for each <option>:
In your buscarpelokitideal function, get the selected value using:
javascript
function buscarpelokitideal() {
var tipotelhado = document.getElementById("tipotelhado").value;
// Now tipotelhado is a string like "1", "2", ..., "8"
// Convert tipotelhado to a number for comparison
var tipotelhadoNum = parseInt(tipotelhado, 10);
}
Step 3: Map the Selected Value to the Structure Info
Use the selected value to access the correct structure information from your kit object. For example:
javascript
var estruturaInfo = kit.Estrutura[tipotelhado].Info;
var estrutura = "";
if (estruturaInfo == 0) {
estrutura = "";
} else if (estruturaInfo == 1) {
estrutura = "Perfil de Alumínio 2.4m";
} else if (estruturaInfo == 2) {
estrutura = "Kit Longarinas 4800MM - Estrutura de solo ROMAGNOLE";
} else if (estruturaInfo == 3) {
estrutura = "Mini Trilho - 100mm (A) x 300mm (C) - Alto (1un)";
} else {
estrutura = "Estrutura não disponível";
}
Step 4: Get the Text of the Selected Option (for Display)
If you want to display the name of the selected roof type, retrieve the text of the selected <option>:
javascript
var tipotelhadoSelect = document.getElementById("tipotelhado");
var selectedOptionText = tipotelhadoSelect.options[tipotelhadoSelect.selectedIndex].text;
Step 5: Use the Variables in Your HTML Template
Now you can use ${estrutura} and ${selectedOptionText} in your HTML template string:
Putting it all together, here's how your buscarpelokitideal function might look:
javascript
function buscarpelokitideal() {
// Get the selected tipotelhado value and convert it to a number
var tipotelhado = document.getElementById("tipotelhado").value;
var tipotelhadoNum = parseInt(tipotelhado, 10);
// Check if a valid option is selected
if (isNaN(tipotelhadoNum)) {
alert("Por favor, selecione um tipo de telhado válido.");
return;
}
// Assuming you have a variable 'kit' that represents the selected kit
// For this example, let's use the first kit in your data
var kit = Kits[0]; // Replace with your actual logic to select the appropriate kit
// Get the estrutura info based on the selected tipotelhado
var estruturaInfo = kit.Estrutura[tipotelhado].Info;
// Map estruturaInfo to a description
var estrutura = "";
if (estruturaInfo == 0) {
estrutura = "";
} else if (estruturaInfo == 1) {
estrutura = "Perfil de Alumínio 2.4m";
} else if (estruturaInfo == 2) {
estrutura = "Kit Longarinas 4800MM - Estrutura de solo ROMAGNOLE";
} else if (estruturaInfo == 3) {
estrutura = "Mini Trilho - 100mm (A) x 300mm (C) - Alto (1un)";
} else {
estrutura = "Estrutura não disponível";
}
// Get the text of the selected option for display
var tipotelhadoSelect = document.getElementById("tipotelhado");
var selectedOptionText = tipotelhadoSelect.options[tipotelhadoSelect.selectedIndex].text;
// Display the result
document.getElementById('kitescolhido').innerHTML = `
<div style="background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); width: 60%; ">
<table width="100%" >
<h1 style="font-size: 22px; color: #333;">${kit.Reconhecimento.Nome} ${kit.Valores.Kwp}kWp - Numero do Kit-${kit.Reconhecimento.Numero}</h1>
<tr>
<td width="70%" align="left">
<p style="font-size: 16px; margin: 10px 0;"><strong>${kit.Placas.Quantidade}X</strong> ${kit.Placas.Info}</p>
<p style="font-size: 16px; margin: 10px 0;"><strong>${kit.Inversores.Quantidade}X</strong> ${kit.Inversores.Info}</p>
<p style="font-size: 16px; margin: 10px 0;"><strong>${selectedOptionText}</strong></p>
<p style="font-size: 16px; margin: 10px 0;">${kit.Valores.Kwh}kWh</p><br>
<span style="font-weight: 500;">Valor:<span style="color: #27ae60;"><strong style="font-weight: 600;">R$100.00</strong></span></span>
</td>
<td align="right" width="30%"><img style="padding: 0 0 0 0; margin: 0 0 0 0;" width="100%" src="https://static.vecteezy.com/system/resources/previews/011/300/023/original/3d-render-solar-panel-front-view-free-png.png">
</td>
</tr>
</table>
</div>
<h1>${kit.Reconhecimento.Nome}</h1>
<p>Placas: ${kit.Placas.Quantidade}X ${kit.Placas.Info}</p>
<p>Inversores: ${kit.Inversores.Quantidade}X ${kit.Inversores.Info}</p>
<p>Estruturas: ${estrutura}</p>
<p>Kwh: ${kit.Valores.Kwh}</p>
<!-- Rest of your content -->
`;
}
Notes:
Ensure kit is Defined Correctly: In the code above, kit is selected from an array Kits. Make sure you have access to this array and select the appropriate kit based on your application's logic.
Handling Preco and Other Properties: If you need to display the price or other properties that depend on tipotelhado, access them similarly using tipotelhado as the key.
Error Checking: Include error checking to handle cases where the user hasn't selected a valid option.
Consistent Variable Names: Make sure to use consistent and meaningful variable names to avoid confusion.
By making these changes, your code should work as intended, mapping the selected roof type to the corresponding numerical value and displaying the correct structure information.
Let me know if you have any questions or need further assistance!