Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <?php
- // Login info and credentials
- $servername = "localhost";
- $username = "yy";
- $password = "xx";
- $dbname = "aa";
- $dbport = "3306";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname, $dbport);
- // Check connection
- if($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- ?>
- <script>
- function ShowComparison(str) {
- if (str=="") {
- document.getElementById("FormLocation").innerHTML="";
- return;
- } else {
- if (window.XMLHttpRequest) {
- // code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp = new XMLHttpRequest();
- } else {
- // code for IE6, IE5
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- document.getElementById("FormLocation").innerHTML = this.responseText;
- }
- };
- xmlhttp.open("GET","form.php",true);
- xmlhttp.send();
- }
- }
- </script>
- </head>
- <body>
- Load form:
- <?php
- // Drop-down to load a form:
- $sql_forms = "SELECT * from Forms";
- $result_forms = $conn->query($sql_forms);
- echo "<select size='5' name='formnumber' onchange='ShowComparison(this.value)'>";
- while ($forms = mysqli_fetch_array($result_forms)) {
- echo "<option value='" .$forms['FormNumber']."'> ".$forms['FormName'] . "</option>";
- }
- echo "</select>";
- ?>
- <br><br>
- <div id="FormLocation"/>
- </body>
- </html>
- <!DOCTYPE HTML>
- <html>
- <head>
- <link rel="stylesheet" type="text/css" href="showdownstyle.css"/>
- <script>
- function CalculateScores() {
- var weight = document.querySelector('input[name="weight1"]:checked').value;
- // Display the score
- document.getElementById("score").innerHTML = "Score: " + weight;
- }
- </script>
- </head>
- <body>
- <div id="FormLocation"/>
- <h1>Product comparison</h1>
- <div id="score">Calculation result here</div>
- <button onclick=CalculateScores()>Calculate</button>
- <br><br>
- <form
- id="ComparisonForm"
- action="form.php"
- name="ComparisonForm"
- method="POST"
- >
- <table class="comparison-table">
- <col width=15%>
- <col width=15%>
- <tr>
- <th class="headingleft">Criteria</th>
- <th class="headingcenter">Criteria weight</th>
- </tr>
- <tr>
- <td class="criteria"><input class="criteriainput" type="text" id="criteria1" name="criteria1"></td>
- <td class="weight">
- <li class="star-weight">
- <input type="radio" onclick="CalculateScores()" name="weight1" id="weight13" value="3"/><label for="weight13"></label>
- <input type="radio" onclick="CalculateScores()" name="weight1" id="weight12" value="2"/><label for="weight12"></label>
- <input type="radio" onclick="CalculateScores()" name="weight1" id="weight11" value="1" checked/><label for="weight11"></label>
- </li>
- </td>
- </tr>
- </table>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement