Why am i getting "undefined" - function

I dont understand why this is coming out as undefined
I have tried multiple ways of getting the values of each each variable and once i got the "value of null" error to go away, this is my issue.
<form class="" action="index.html" method="post">
Principal: <br>
<input type="text" name="principal" value="" id="prin"> <br>
Amount of Payments:<br>
<input type="text" name="payments" value="" id="payment"> <br>
Interest Rate: <br>
<input type="text" name="interest" value="" id="rate">
</form>
<br>
<button type="button" name="button" id="submit" onclick="interestTot()">Calculate</button>
<div id="div1">
</div>
</body>
</html>
let principal = document.querySelector("#principal");
let payment = document.querySelector("#payment");
let rate = document.querySelector("#rate");
let interest ;
if (document.querySelector("#principal)" != null) {
principal = parseInt(document.querySelector('#principal').value);
};
if (document.querySelector("#payment") != null) {
payment = parseInt(document.querySelector('#payment').value);
};
if (document.querySelector("#rate") != null) {
rate = parseInt(document.querySelector('#rate').value);
};
function interestTot() {
if (principal > 0) {
interest = rate / payment;
}
document.querySelector("#div1").innerHTML= interest
};

Related

how to left text search in input after submit

I have search input. When I write a number to find something (this is an HTTP request) I have some results but my number from input disappeared. How can I leave it?
div class="control is-expanded">
<input
name="request_id"
class="input"
placeholder="Request ID"
/>
</div>
<div class="control">
<input type="submit" name="submit" class="button is-link" />
</div>
The HTTP request in on the beckent, which I didnt write. I do only frontend. Can I change this or not?
HTML:
<form method="post" action="" onSubmit="return saveComment();">
<input type="text" name="request_id" class="input" placeholder="Request ID from Furia" />
<input type="submit" name="submit" class="button is-link" />
</form>
JavaScript:
document.getElementById("request_id").value = localStorage.getItem("comment");
function saveComment() {
var comment = document.getElementById("request_id").value;
if (comment == "") {
alert("Please enter a comment in first!");
return false;
}
localStorage.setItem("comment", comment);
alert("Your comment has been saved!");
location.reload();
return false;
}

ASP Razor Web Pages - Form Submit is Moving My Data

When I submit my Login email (aka username), I want to keep it in my Login form.
When I submit my Register email (aka username), I want to keep it in my Register form.
What is happening is: when I submit my Login form, it writes the email (aka username) to the Register form. Please see image for what is happening.
#{
Page.Title = "Login";
var username = "";
var password = "";
var errorMessage = "";
var confirmPassword = "";
var regMsg = "";
var confToken = "";
var emailBody = "";
var minPass = 2;
var maxPass = 5;
if (!IsPost) {
if (WebSecurity.IsAuthenticated) {errorMessage = String.Format("You are already logged in. (Username: {0})", WebSecurity.CurrentUserName);}
}
if(WebSecurity.IsAuthenticated){
errorMessage = String.Format("You are already logged in. (Username: {0})", WebSecurity.CurrentUserName);
}
if(IsPost){
// Login Form
if (Request.Form["loginSub"] != null){
regMsg = "";
username = Request["username"];
password = Request["password"];
if(WebSecurity.Login(username,password,true)){
Response.Redirect("~/Profile");
}
else
{
errorMessage = "Invalid Username or Password. Please try again.";
}
}
// Register Form
if (Request.Form["registerSub"] != null){
WebSecurity.Logout();
errorMessage = "";
username = Request["username"];
password = Request["password"];
confirmPassword = Request["confirmPassword"];
try {
var mail = new System.Net.Mail.MailAddress(username);
} catch {
regMsg += "<br>Invalid email format.";
}
if (password != confirmPassword) {regMsg += "</br>Passwords don't match.";}
if (WebSecurity.UserExists(username)) {regMsg += String.Format("</br>User '{0}' already exists.", username);}
if (password.Length < minPass || password.Length > maxPass) {regMsg += "</br>Password doesn't meet length requirement.";}
if (regMsg == "") {
WebSecurity.CreateUserAndAccount(username,password,null,false); //Switch with "true" token
regMsg = String.Format("{0} created.", username);
Response.Write("<script>alert('Email verification sent! Please check your email to activate your account.');</script>");
//Response.Write("<script>location.href = 'Default.cshtml';</script>");
}
}
}
}
<style>header {visibility: hidden;}</style>
<body>
<h1>MySite</h1>
<p>
#if(errorMessage != ""){<span>#Html.Raw(errorMessage)</span>}
#if(regMsg != ""){<span>#Html.Raw(regMsg)</span>}
</p>
<fieldset class="fs100">
<legend>Login</legend>
<form method="post" name="login">
#if(WebSecurity.IsAuthenticated){
<p>You are currently logged in as #WebSecurity.CurrentUserName.
Log out
</p>
}
<p>
<label for="username">Email Address:</label><br/>
<input type="text" name="username" id="username" value="" />
</p>
<p>
<label for="password">Password:</label><br/>
<input type="password" name="password" id="password" value="" />
</p>
<p>
<input type="submit" name="loginSub" value="Submit" />
</p>
<p>Forgot Password?</p>
</form>
</fieldset>
<fieldset>
<legend>Register</legend>
<form method="post" name="register">
<p>
<label for="username">Email Address:</label><br/>
<input type="text" name="username" id="username" value='#Request["username"]' />
</p>
<p>
<label for="password">Password #minPass-#maxPass Characters:</label><br/>
<input type="password" name="password" id="password" value="" />
</p>
<p>
<label for="confirmPassword">Confirm Password:</label><br/>
<input type="password" name="confirmPassword" id="confirmPassword" value="" />
</p>
<p>
<input type="submit" name="registerSub" value="Register" />
</p>
</form>
</fieldset>
</body>
Your code is echoing the value from the request in the second form.
If you don't want it to do that, change your code to do something else.
You may want to change each form to have unique field names.

Correctly using gumbo-parser to iterate and find the things I need?

I'm working on a pure C99 practising project which can do a login simulation for our school's CAS login system.
Now I'm trying to use Gumbo HTML parser to parse our school's login page. Here is the form section and I need to get the login ticket from it before I run the POST request to submit the form, which is the "hidden" type input element with name "lt". (i.e. line with <input type="hidden" name="lt" value="LT-000000-b4LktCXyzXyzXyzXyzXyzXyz" />, and I need to parse the "value").
I've wrote some code, but it seems cannot find out this input element. Here is my C program's function:
const char * parse_login_ticket_old(char * raw_html)
{
// Parse HTML into Gumbo memory structure
GumboOutput * gumbo_output = gumbo_parse(raw_html);
// Prepare the node
GumboNode * gumbo_root = gumbo_output->root;
assert(gumbo_root->type == GUMBO_NODE_ELEMENT);
assert(gumbo_root->v.element.children.length >= 2);
const GumboVector* root_children = &gumbo_root->v.element.children;
GumboNode* page_body = NULL;
for (int i = 0; i < root_children->length; ++i)
{
GumboNode* child = root_children->data[i];
if (child->type == GUMBO_NODE_ELEMENT && child->v.element.tag == GUMBO_TAG_BODY)
{
page_body = child;
break;
}
}
assert(page_body != NULL);
GumboVector* page_body_children = &page_body->v.element.children;
for (int i = 0; i < page_body_children->length; ++i)
{
GumboNode* child = page_body_children->data[i];
GumboAttribute * input_name_attr = gumbo_get_attribute(&child->v.element.attributes, "name");
if (child->type == GUMBO_NODE_ELEMENT && child->v.element.tag == GUMBO_TAG_INPUT && strcmp(input_name_attr->value, "lt") == 0)
{
GumboAttribute * input_value_attr = gumbo_get_attribute(&child->v.element.attributes, "value");
return input_name_attr->value;
}
}
return NULL;
}
In case someone need for debugging, here is a example of our schools page. Possible sensitive data has been removed.
<body>
<div id="wrapper">
<div id="contentArea" role="main">
<div class="form login" role="form">
<h2 class="hidden">Login</h2>
<form id="fm1" class="fm-v clearfix" action="/schoolcas/login?jsessionid=1234567890" method="post"><div class="formRow">
<label for="username" class="label">Student ID</label>
<div class="textBox">
<input id="username" name="username" class="schoolcas text" aria-required="true" type="text" value="" size="25" maxlength="25"/></div>
</div>
<div class="formRow">
<label for="password" class="label">Password</label>
<div class="textBox">
<input id="password" name="password" class="schoolcas text" aria-required="true" type="password" value="" size="25" autocomplete="off"/></div>
</div>
<div class="formRow">
<input type="hidden" name="lt" value="LT-000000-b4LktCXyzXyzXyzXyzXyzXyz" />
<input type="hidden" name="execution" value="e2s1" />
<input type="hidden" name="_eventId" value="submit" />
<input class="button grey submit" name="submit" value="Login" type="submit" />
</div>
</form>
</div>
</div>
</div>
</body>
Anyway, my program seems just stop at the top of the body element and it returns NULL later on.
So I would like to know how to do a correct search, and find out the input element I need?
I've figured it out by myself from the Google sample code (https://github.com/google/gumbo-parser/blob/master/examples/find_links.cc).
Here's the code. It's crappy but it works anyway.
const char * find_attribute(GumboNode * current_node, GumboTag element_tag_type,
char * element_term_key, char * element_term_value, char * desired_result_key)
{
const char * lt_token = NULL;
// Return NULL if it is in WHITESPACE
if (current_node->type != GUMBO_NODE_ELEMENT)
{
return NULL;
}
// Set the element's term key,
// e.g. if we need to find something like <input name="foobar"> then element search term key is "name",
// and element search value is "foobar"
GumboAttribute* lt_attr = gumbo_get_attribute(&current_node->v.element.attributes, element_term_key);
if (lt_attr != NULL && current_node->v.element.tag == element_tag_type && (strcmp(lt_attr->value, element_term_value) == 0))
{
lt_token = gumbo_get_attribute(&current_node->v.element.attributes, desired_result_key)->value;
return lt_token;
}
GumboVector* children = &current_node->v.element.children;
for (unsigned int i = 0; i < children->length; ++i)
{
lt_token = find_attribute(children->data[i], element_tag_type,
element_term_key, element_term_value, desired_result_key);
// Force stop and return if it gets a non-null result.
if(lt_token != NULL)
{
return lt_token;
}
}
}

Sending json data to google form with textarea and select tag

I created an application which sends json data to a google form with ajax. My problem is that I'm not able to send all the data I wish, which means that I'm not able to send some content inside a textarea and a select tag. I'm working with the url, unfortunately I had to use some hidden content in order to move some data to from a page to another page, if I wont' I'm not able to get some data.
Here is my code: The javascript:
$( document ).ready(function() {
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
function postContactToGoogle() {
var full_name = getParameterByName('full_name');
var home_address = getParameterByName('home_address');
var email = getParameterByName('email');
var phone_number = getParameterByName('phone_number');
var condition = getParameterByName('condition');
var extra = getParameterByName('extra');
var when_to_sell = getParameterByName('when_to_sell');
console.log(full_name, home_address, email, phone_number, condition, extra, when_to_sell);
var google_url = "https://docs.google.com/forms/d/e/1FAIpQLSdqMQL_dzhdFSVpuVtlcfIa4xHe9DNP8yozB1ncAB2e_byBJQ/formResponse";
if (full_name !== "" || email !== "" || phone_number !== "" || home_address !== "" || condition !== "" || extra !== "" || when_to_sell !== "")
{
$.ajax({
url: google_url,
data: {
"entry.515947838": full_name,
"entry.190795925": email,
"entry.1306603567": phone_number,
"entry.1032461271": home_address,
"entry.100378601": condition,
"entry.637314286": extra,
"entry.608122467": when_to_sell
},
type: "POST",
dataType: "json",
statusCode: {
0: function () {
},
200: function () {
}
}
});
}
}
postContactToGoogle();
});
And here's the html which is creating me a lot of problem: This is a page when I'm collecting some data that I will later send with the ajax
<form action="step-3.html" id="form-step2">
<div class="form-control full-width">
<label for="condition">What conditions is the property in?</label>
<select id="condition" name="condition">
<option value="Good">Good</option>
<option value="Fair">Fair</option>
<option value="Bad">Bad</option>
</select>
</div>
<div class="form-control full-width">
<label for="extra">Any updates, amenities or extras?</label>
<textarea name="extra" id="extra" placeholder="e.g: recent reno, pool etc." rows="3"></textarea>
</div>
<div class="form-control full-width">
<label for="when_to_sell">When do you want to sell?</label>
<select id="when_to_sell" name="when_to_sell">
<option value="Immediately">Immediately</option>
<option value="Next 1-3 months">Next 1-3 months</option>
<option value="Next 3-6 months">Next 3-6 months</option>
</select>
</div>
<div class="form-control full-width">
<label>Are you currently working with a Real Estate Agent?*</label>
<input checked="checked" id="working_for_real_estate_agent_no" name="working_for_real_estate_agent" type="radio" />
<label class="radio-label" for="working_for_real_estate_agent_no">No</label>
<input id="working_for_real_estate_agent_yes" name="working_for_real_estate_agent" type="radio" />
<label class="radio-label" for="working_for_real_estate_agent_yes">Yes, I am working with a Realtor.</label>
<div class="asteriks">*We ask this to ensure there is no conflict of interest.</div>
</div>
<div class="form-control full-width">
<input id="home_address" name="home_address" type="hidden" />
<div class="home-evaluation-option-container">
<div class="home-evaluation-option">
<input id="exact-market-value" name="exact-market-value" type="button" value="Send Property Details" />
</div>
</div>
</div>
</form>
And here is the hack that I tried, which unfortunately works only with the input tag:
<form action="step-4.html" id="form-step2">
<div class="form-control full-width">
<input name="full_name" placeholder="Full Name" type="input" data-validation="length alphanumeric" data-validation-length="min1" data-validation-error-msg="Please, insert your name" />
</div>
<div class="form-control full-width">
<input id="email" name="email" placeholder="Email" type="input" data-validation="email" />
</div>
<div class="form-control full-width">
<input id="phone_number" name="phone_number" placeholder="Phone Number" type="input" name="home-phone" data-validation="number" />
</div>
<input id="home_address" name="home_address" type="hidden" class="hide" />
<select id="condition" name="condition" class="hide">
<option value="Good">Good</option>
<option value="Fair">Fair</option>
<option value="Bad">Bad</option>
</select>
<textarea name="extra" id="extra" class="hide"></textarea>
<select id="when_to_sell" name="when_to_sell" class="hide">
<option value="Immediately">Immediately</option>
<option value="Next 1-3 months">Next 1-3 months</option>
<option value="Next 3-6 months">Next 3-6 months</option>
</select>
<div class="form-control submit-button">
<input name="submit" type="submit" value="Generate Report" />
</div>
</form>
Any thought in order to collect data from a select or a text area?
Here is the page where you can find the code in action:
http://homeworth.online/hockinghomesteam/
Here is an example of how you can get the value out of a textarea element:
<!DOCTYPE html>
<html>
<body>
<textarea id="idExtra_Info">
Some content
</textarea>
<button type="button" onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var x = document.getElementById("idExtra_Info").value;
alert(x);
}
</script>
</body>
</html>

Why wont <button type="submit"> work?

I have a standard HTML form, and the button is not working. I know it is directing to the correct page, and as far as I can see everything looks perfect.
It lets me click the button, but then nothing happens, it doesn't direct me to the send.php page or anything.
<form method="post" action="http://www.URL.net/send.php">
<p>
<label for="name">Name <span class="required">*</span></label>
<input type="text" name="name" id="name">
</p>
<p>
<label for="email">Email <span class="required">*</span></label>
<input type="text" name="email" id="email">
</p>
<p>
<label for="subject">Subject</label>
<input type="text" name="subject" id="subject">
</p>
<p>
<label for="subject">Message <span class="required">*</span></label>
<textarea name="message" id="message" cols="45" rows="10"></textarea>
</p>
<div class="fBtn">
<button type="submit" name="submit" id="submit" class="regButton"><i class="icon-paper-plane"></i>Send Message</button>
</div>
</form>
Also, I have tried using <input type="submit" name="submit" id="submit" class="regButton" value="Send Message" /> as well, but it also isn't working for some odd reason.
Tested in Chrome and IE11.
EDIT Here is the JS for form vaildation:
$('#submit').click(function(){
$('input#name').removeClass("errorForm");
$('textarea#message').removeClass("errorForm");
$('input#email').removeClass("errorForm");
var error = false;
var name = $('input#name').val();
if(name == "" || name == " ") {
error = true;
$('input#name').addClass("errorForm");
}
var msg = $('textarea#message').val();
if(msg == "" || msg == " ") {
error = true;
$('textarea#message').addClass("errorForm");
}
var email_compare = /^[a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i;
var email = $('input#email').val();
if (email == "" || email == " ") {
$('input#email').addClass("errorForm");
error = true;
}else if (!email_compare.test(email)) {
$('input#email').addClass("errorForm");
error = true;
}
if(error == true) {
return false;
}
var data_string = $('.contactForm form').serialize();
$.ajax({
type: "POST",
url: $('.contactForm form').attr('action'),
data: data_string,
success: function(message) {
if(message == 'SENDING'){
$('#success').fadeIn('slow');
}
else{
$('#error').fadeIn('slow');
}
}
});
return false;
});
You appear to have some JavaScript that automatically submits every form using AJAX. Since you’re on the domain trishajohnson.net, the same-origin policy prevents JavaScript from opening requests to a (slightly) different domain – www.trishajohnson.net.
There’s an easy fix, though – just use the path part. It’s cleaner anyway.
<form method="POST" action="/tj/send.php">