-1

I wanted to make a communication form and I literally copy pasted the code of a previously working one. The only changes I have made to the code are the text parts and CSS. All the name and ids are the same including the form. As I previously stated, literally a copy paste. I checked the console tab, no errors at all. At this point I'm confused. Any help is appreciated.

Code:

<DOCTYPE html>
<html>
<head>
<link REL="STYLESHEET" TYPE="TEXT/CSS" HREF="STYLES.css">
<title>ΣΕΛΙΔΑ ΕΠΙΚΟΙΝΩΝΙΑΣ</title>
</head>
<body>
<form name="CForm" id="CForm" method="post">
<h3>ΦΟΡΜΑ ΕΠΙΚΟΙΝΩΝΙΑΣ</h3>


  <form name="myForm" id="form1"  onsubmit="return validateForm()" method="post">
    <label for="fname">ΟΝΟΜΑ ΚΑΙ ΕΠΩΝΥΜΟ </label>
    <input type="text" id="fname" name="fname" placeholder="Ονομα&Επωνυμο" class="otherCFcss">

    <label for="tel">ΤΗΛΕΦΩΝΟ</label>
    <input type="text" id="tel" name="tel" placeholder="Τηλεφωνο.." class="otherCFcss">

    <label for="lname">Email</label>
    <input type="email" id="email" name="email" placeholder="something@something.com"><br>

    <label for="subject">ΘΕΜΑ</label>
    <textarea id="message" name="message" placeholder="Γραψε κατι.." style="height:200px" class="otherCFcss"></textarea>

   <input type="submit" id="submitbutton" value="ΑΠΟΣΤΟΛΗ">
   <input type="reset" id="resetbutton" value="ΑΚΥΡΩΣΗ">
  </form>


</body>
</html>
<script>
    var a = sessionStorage.getItem("a");
    var b = sessionStorage.getItem("b");
    var c = sessionStorage.getItem("c");
    var d = sessionStorage.getItem("d");
    document.getElementById("fname").value= a;
    document.getElementById("tel").value= b;
    document.getElementById("email").value= c;
    document.getElementById("message").value= d;
    function send() {
        window.location.href = "mailto:dimtrispap1999@gmail.com?subject=Αυτόματο μήνυμα &body="+"Όνοματεπωνυμο:  "+ a +"%0A"+"Τηλέφωνο:"+"  "+ b +"%0A"+"Αίτημα,ερωτημα:  "+d;
    }

    function validateForm() {
        var x = document.forms["myForm"]["fname"].value;
        var y = document.forms["myForm"]["tel"].value;
        var z = document.forms["myForm"]["email"].value;
        var e = document.forms["myForm"]["message"].value;
        if (x == "" || y == "" || z == "" || e == ""){
            alert("Fill in the blanks");
        } else {
            var confirmwindow = window.open("", "_black", "width=560,height=190");
            confirmwindow.document.writeln("<h3>Σιγουρα θελετε να στειλετε την παρακατω φορμα?</h3>");
            confirmwindow.document.write("<b>Name*: </b>" + x + "<br>");
            confirmwindow.document.writeln("<b>Τηλεφωνο*: </b>" + y + "<br>");
            confirmwindow.document.writeln("<b>Email*: </b>" + z + "<br>");
            confirmwindow.document.writeln("<b>Message*: </b><br>" + e + "<br><br>");
            confirmwindow.document.write("<input type='submit' onclick='opener.send()' id='submitbutton' value='ΑΠΟΣΤΟΛΗ'>"+ " ");
            confirmwindow.document.writeln("<input type='button' onclick='window.close();' id='resetbutton' value='cancel'>");
        }
        return false;
    }
</script>

I also tried to add a variable outside the functions in both the previous and the current code.Something like that var x=document.forms["myForm"]["fname"].value;.In the previous code (the working one) there were no errors. In the current one I get from the console this error:

Uncaught TypeError: Cannot read property 'fname' of undefined at
elidaepikoinwnias.html:35.

Line 35 is the line where I add the variable.Once I remove it the error is gone but still the JS code doesn't work.

Moob
  • 14,420
  • 1
  • 34
  • 47

1 Answers1

1

Looks like you have a redundant and unclosed form - cForm

Remove this line

<form name="CForm" id="CForm" method="post">

You should not be nesting forms, check this

gurvinder372
  • 66,980
  • 10
  • 72
  • 94