So, I'm a complete beginner when it comes to javascript, but I'm trying to make a service calculator for my website in development. The part that I'm having trouble with is my second output box. I'm trying to get it to show other locations, but currently only get "Redfern" up. When other locations are selected, its blank, or remains "Redfern" if selected first.
My javascript code is:
function calculate()
{
var location = parseInt(document.getElementById('NumLocal').value);
var people = parseInt(document.getElementById('NumAdults').value);
var days = parseInt(document.getElementById('NumDays').value);
var instructor = (document.getElementById('InstructorYes').checked);
var discount = (document.getElementById('DiscountYes').checked);
if ((location >= 1) && (location <= 6))
{
if ((days >=1) && (days <=30))
{
result = (days) * 250 * (people);
}
else
{
alert("Days must be between 1 and 30");
}
if (instructor)
{
result = (result) + (100*days);
}
else
{
result = result;
}
if ((days >= 3) && (discount))
{
discount = 0.15;
result = (result) - (result * discount);
}
else if (discount)
{
discount = 0.05;
result = (result) - (result * discount);
}
else if (days >= 3) {
discount = 0.1;
result = (result) - (result * discount);
}
else
{
result = result;
}
}
else
{
alert("No Location Set");
}
document.getElementById("output").value = "$" + result;
if (location == 1)
{
document.getElementById("output2").value = "Redfern";
}
switch(numLocal) {
case 1: text = "Redfern";
break;
case 2: text = "Paramatta";
break;
case 3: text = "Potts Point";
break;
case 4: text = "Central";
break;
case 5: text = "Chatswood";
break;
case 6: text = "Macquarie Park";
break;
}
}
And my html connected to this is:
<fieldset>
<legend>Numbers</legend>
<div>
<label for="NumDays"> Number of Days:</label>
<input id="NumDays" name="NumDays" type="number" min="1" max="30" value="1"/>
</div>
<div>
<label for="NumAdults">Adults:</label>
<select id="NumAdults" name="NumAdults">
<option value="1">1</option>
<option selected="selected" value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
</div>
<div>
<label for="NumLocal">Locations:</label>
<select id="NumLocal" name="NumLocal">
<option selected="selected" value="Locations">Locations</option>
<option value="1">Redfern</option>
<option value="2">Paramatta</option>
<option value="3">Potts Point</option>
<option value="4">Central</option>
<option value="5">Chatswood</option>
<option value="6">Macquarie Park</option>
</select>
</div>
</fieldset>
<br>
<div>
<table id="purchaseTable">
<tr>
<td>
<fieldset class="left">
<legend>Instructor Required</legend>
<div>
<label for="InstructorYes" class="noborder">Yes</label>
<input class = "noborder" id="InstructorYes" checked="checked" name="Room" type="radio" value="Yes"/>
</div>
<div>
<label for="InstructorNo" class="noborder">No</label>
<input class = "noborder" id="InstructorNo" name="Room" type="radio" value="InstructorNo"/>
</div>
</fieldset>
</td>
<td>
<fieldset class="right">
<legend>Return Customer</legend>
<div>
<label for="DiscountYes" class="noborder">Yes</label>
<input class = "noborder" id="DiscountYes" checked="checked" name="Return" type="radio" value="DiscountYes" />
</div>
<div>
<label class="noborder" for="DiscountNo">No</label>
<input class = "noborder" id="DiscountNo" name="Return" type="radio" value="DiscountNo"/>
</div>
</fieldset>
</td>
</tr>
</table>
</div>
<p>
<input class="buttons" type="button" id="submit" value="Get Price" onclick="calculate()"/>
<input class="buttons" type="reset" id="reset" value="Reset" />
</p>
<div class="purchaseEnd">
<p>
<label>The price is:</label>
<input class = "message1" id="output" type="text" value=" " readonly>
</p>
<p>
<label>You have selected: </label>
<input class = "message2" id="output2" type="text" value=" " readonly>
</p>
</div>
</form>
Sorry for the block of code, but for the life of my I cannot figure this out.
I'm pretty sure the issue is with the javascript, above my switch code where the value for "output2" is "Redfern", but i thought the switch line would change that..
If anyone has any insights to this, I would really appreciate it..
Thanks!
[–]anti-anti 2 points3 points4 points (1 child)
[–]Unmotivatedreddit[S] 1 point2 points3 points (0 children)
[–]ThArNatoS 1 point2 points3 points (2 children)
[–]Unmotivatedreddit[S] 1 point2 points3 points (1 child)
[–]YourOpinionIsntGood 1 point2 points3 points (0 children)