Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  15] [ 4]  / answers: 1 / hits: 17038  / 12 Years ago, fri, august 10, 2012, 12:00:00

I have a small calculator that I'm adding to my html. It has a few dropdowns to select stuff and when a person hits a submit button, I'd like to display a picture below the calculator in my html. I've tried using a javascript function with: document.write() but that clears the whole page. Is there a way that I can get a javascript function to run which only adds a picture to my page when a submit button is clicked?



Here's a BASIC outline of my code with the part I'm having trouble with:



<html>

<head>
<script type=text/javascript>

function calc_rate() {

//code that displays a message after the submit button is hit
document.write(answer);
}

</script>

</head>
<body>


<table>


<tr>
<td class=rate_calc_label>Select Your Option Type:</td>
<td><select name=type1>
<option></option>
<option>1</option>
<option>2</option>
<option>3</option>
</select></td>
</tr>


<tr>
<td class=rate_calc_label>Select The Second Number:</td>
<td><select name=type2>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
</select></td>
</tr>


<tr>
<td><input type=submit value=Submit name=calc_button onclick=calc_rate()/></td>
<td></td>
</tr>

</table>

</body>
</html>


would it be possible to use some kind of inner-HTML? That's what I got from others on stockoverflow but I'm still a little confused


More From » html

 Answers
-1

You need a placeholder element for your output. Then set the innerHTML for that element:



<div id='answer'></div>


then:



document.getElementById('answer').innerHTML = answer is: + yourdata

[#83710] Thursday, August 9, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
frederickmohamedw

Total Points: 21
Total Questions: 123
Total Answers: 105

Location: The Bahamas
Member since Tue, Apr 27, 2021
3 Years ago
frederickmohamedw questions
Wed, Sep 23, 20, 00:00, 4 Years ago
Sat, Jul 18, 20, 00:00, 4 Years ago
Sun, Apr 26, 20, 00:00, 4 Years ago
Sat, Jan 11, 20, 00:00, 4 Years ago
Fri, Dec 27, 19, 00:00, 4 Years ago
;