0
<div class="comment">
          <form name="myform" onsubmit="return validateform()">
            <label for="fname">Full Name</label>
            <input type="text" id="fname" name="fullname" placeholder="Your name..">

            <label for="email">E-mail</label>
            <input type="text" id="email" name="email" placeholder="Your e-mail..">

            Rate us<br>
            <input type="radio" id="radio1" name="rate">
            <label for="radio1">Poor</label>
            <input type="radio" id="radio2" name="rate">
            <label for="radio2">Good</label>
            <input type="radio" id="radio3" name="rate">
            <label for="radio3">Excelent</label>

            <br>
            <label for="subject">Comments</label>
            <textarea id="subject" name="subject" placeholder="Write something.." style="height:200px"></textarea>

            <input type="submit" value="Submit">
          </form>
        </div>

        <script type="text/javascript">
            function validateform(){
                var name=document.forms["myform"]["fname"].value;
                var poor = document.getElementById("radio1").checked;
            var good = document.getElementById("radio2").checked;
            var excelent = document.getElementById("radio3").checked;
            var text = document.forms["myform"]["subject"].value;

                if (name == "" || name==null || !name.match(/^[a-zA-Z]+$/)) {
                    alert("Please enter name");
                    return false;
                }
                if (text == "" || text==null || !text.match(/^[a-zA-Z]+$/)) {
                    alert("Please enter valid text");
                    return false;
                }
                else if (poor==true) {
                alert(" Dear "  + name +    " , We appriciate your feedback. You have rated our site as POOR and your comment was " + text);
            return false;
            }
            else if (good==true) {
                alert(" Dear "  + name +    " , We appriciate your feedback. You have rated our site as GOOD and your comment was " + text);
            return false;
            }
                else if (excelent==true) {
                alert(" Dear "  + name +    " , We appriciate your feedback. You have rated our site as EXCELENT and your comment was " + text);
            return false;
            }

            }
        </script>

This is part of the code of a comment section I'm creating.I've done the validation for the name and the text area, but i can't find a way to get an alert message saying, "Dear (name). We appreciate your feedback. You have rated our site as (relevant radio button name) and your comment was (comment on comment area)".Can someone tell me how to display this alert message.

(No need validation for the e-mail)

DDSasikala
  • 43
  • 1
  • 7
  • Check out this: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email – Rob Jul 25 '18 at 12:03
  • 1
    Possible duplicate of [How to validate an email address in JavaScript?](https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript) – sjahan Jul 25 '18 at 12:05

3 Answers3

1
<input type="email" id="email" name="email" placeholder="Your e-mail..">

There is a input type='email' which, if submitted, will check if this is a valid email.

See documentation here

Hearner
  • 2,711
  • 3
  • 17
  • 34
0

I know this is not what you asked for exactly, but this is a more error proof way to perform validation, and it is really easy to use. https://validatejs.org/, check it out.

Elie
  • 321
  • 3
  • 11
-1

i've found a pattern for an email adress => /^[a-z0-9._%+-]+@[a-z0-9.-]+.[a-z]{2,4}$/;

I don't know what the input is gonna be of the textarea but you can check if its filled or not like you did here => name == ""