0

I know this is probably really simple but I'm just starting out and I can't seem to make the connection between the material on the subject and actually getting it to work.

I just want to pass the values contained within my input boxes into the paragraph field below after the submit button is clicked. I got it to work with hardcoded values but I can't seem to get any variables to pass into it.

<!DOCTYPE html>
<html = "en">
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="/dustmonitor/script/c3.min.css">
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<head>

<title> Test entry form webpage </title>
</head>
<body>

<form id="form1">
Start Datetime:<br>
<input type="text" name="startDate" id="startDate" class="Date"><br>
End Datetime <br>
<input type="text" name="startDate" id="endDate" class="Date"><br>
Parameter<br>
<input type="checkbox" class="parameter" value="PM2.5">PM2.5<br>
<input type="checkbox" class="parameter" value="PM10">PM10<br>
<input type="submit">
</form>

<script>
$(document).ready(function(){
    //alert("inside first");
    $("#form1").submit(function(){
        //alert("inside submit");

        var startD = $(".Date");
        $(function).text(.startD);

        //event.preventDefault();

        alert("after");
        });
});
</script>
<p> </p>
</body>
</html>

I commented out the event.preventDefault because I wasn't getting to the alert that was after it so I figured I was using that incorrectly as well.

I'm pretty sure my issue is coming from the .text attempt and that my variable is being stored well.

Thanks for the help.

1 Answer 1

3

You have to use .val() to get the value of an input.

When you use a variable, you don't put . before it.

To select the paragraph, you need to use $("p"), not $(function).

$("#form1").submit(function(){
    //alert("inside submit");

    var startD = $(".Date").val();
    $("p").text(startD);

    //event.preventDefault();

    alert("after");
});
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.