How can my html not read my js [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
This is just 1 html file but whenever I seperate them I have
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form name="registerform" onsubmit="return validateForm()">
First name:<br>
<label>
<input type="text" required="required" name="getfirstname">
</label><br>
Last name:<br>
<input type="text" required="required" name="lastname"><br>
Email address:<br>
<input type="email" required="required" name="email"><br>
Password:<br>
<input type="password" required="required" name="password"><br>
Password2:<br>
<input type="password" required="required" name="password2"><br>
<input type="submit" value="Submit">
</form>
and
window.validateForm=function() {
alert(document.forms["registerform"]);
var x = document.forms["registerform"]["password"].value;
var y = document.forms["registerform"]["password2"].value;
if (y != x){
alert("The passwords do not match. Please try again!");
return false;
}
return true;
}</script>
</body>
</html>
When I got the full js just under my form, it does execute the script.
But when I put
<script>"/JS/Form.js"</script>
it doesn't work...
Any idea?

I would assume that you want to load your javascript file from a relative path (relative to your html page) rather than an absolute path. Absolute paths start with a / (slash).
Try
<script src="js/script1.js"></script>
To debug it right click your page and click on the javascript src value. A page with the file content gets shown. It will tell you if the src does not point to an actual file available on your server.

Related

Creating an HTML form to interact with REST API [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
I am trying to write an HTML form to interact with a REST API.
This is what I have so far, but I'm not sure what I need to do to actually get it to interact with the REST API, how do I link them?
<!DOCTYPE html>
</html>
<head>
</head>
<body>
<form id="myForm">
<label for="name">Name</label><br>
<input type="text" id="name" name="name"><br>
<label for="password">Password</label><br>
<input type="text" id="password" name="password"><br>
</form>
</body>
You are almost there. First of all, your form needs to be submittable. You can achieve this by adding a submit input:
<!DOCTYPE html>
</html>
<head>
</head>
<body>
<form id="myForm" action="/action_page.php">
<label for="name">Name</label><br>
<input type="text" id="name" name="name"><br>
<label for="password">Password</label><br>
<input type="text" id="password" name="password"><br>
<input type="submit" value="Submit">
</form>
</body>
Now, your structure is ready to be used. On the other end, you have a RESTful API, which should handle properly the request your form is sending. You can achieve that using the action attribute of your form tag.

Php : cant sumbit the good form [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Sorry for my spelling
Hi, im trying to make a website showing internet forfeit, so in mySQL database i put all my information then I print it on my web page, the the user click on the forfeit he wants, it brings him to an other page that shows all the forfeit informations... In the while(), I'm making unique form for each forfeit, then on the
The problem here is that the only form sumbitted is the last one created
include_once "DataBase/db.php";
if($internet->num_rows != 0){
while($rows = $internet->fetch_assoc()){
$nom = $rows["nom"];
$id = $rows["id"];
$tech = $rows["technologie"];
$telechargement = $rows["telechargement"];
$televersement = $rows["televersement"];
$utilisation = $rows["utilisation"];
$prix= $rows["prix"];
echo '
<form method="POST" action="Fournisseurs/Videotron.php" id="'.$id.'">
<div class="boxes">
<div class="[ price-option price-option--high ]">
<div class="price-option__detail">
<span class="price-option__cost">'.$nom.'<br>$'.$prix.'</span>
</div>
<input type="hidden" name="id" value="'.$id.'"></input>
<input type="hidden" name="nom" value="'.$nom.'"></input>
<input type="hidden" name="tech" value="'.$tech.'"></input>
<input type="hidden" name="telechargement" value="'.$telechargement.'"></input>
<input type="hidden" name="televersement" value="'.$televersement.'"></input>
<input type="hidden" name="utilisation" value="'.$utilisation.'"></input>
<input type="hidden" name="prix" value="'.$prix.'"></input>
<div class="price-option__purchase">
Submit
</div>
</div>
</div>
';
}
}
You can see what i'm talking about here : http://fournisseursquebec.com/Forfaits.php
just select internet
Thank you!
You are missing the closing </form> tag for every box. Now you have one big form with a lot of repeated fields:
<form method="POST" action="Fournisseurs/Videotron.php" id="'.$id.'">
box 1:
<input type="hidden" name="id" value="'.$id.'"></input>
.... box 2:
<input type="hidden" name="id" value="'.$id.'"></input>
...
The name attribute of the various input is the one that is sent and should be unique inside every form.
Just add the </form> tag in your while loop and it should work.

How To Save text in Textbox

Hi I'm kind of a beginner in coding I've been doing it for a couple of months doing basic things. I'd like to know how to make a basic account sign in type of thing, where you type in your username and password that you want press submit then it saves those to the html file and remember it when I exit and that the next time you type in your username and password it will recognize the username and password. Any thoughts? The code I have so far...
<!DOCTYPE HTML>
<html>
<head>
<title>Sign Up!!!</title>
</head>
<body>
<form>
<input type="text" name="UserName" value="Username">
<br>
<input type="text" name="Password" value=Password">
<br>
<input type="submit" name="SU" value="Sign Up" onclick="su()"
</form>
<script>
function su(){
var su = document.getElementsByName("Username")[0].value;
var su2 = document.getElementsByName("Password")[0].value;
}
</script>
</body>
</html>
I have the var su to get what's in the text boxes, but I'm not sure on how to save those two things. What do I do?
There are some ways to do that, but there are very simple way in HTML5, just put <input type="text"> for the user name and <input type="password"> and the web browser will automatically cache it.
There are many youtube tutorials for your answers. However, you will mainly need php. Here is a link to a tutorial about register and login.

How to access information in a javascript file that was send from a form?

I have this following code:
<form action="main.js">
<input type="text" required="required" pattern="[a-zA-Z]+" />
<input type="submit" value="Submit" />
</form>
When i click the submit button, the information that was in the input should be sent to my file "main.js". But there is nothing in "main.js". I want that "main.js" file would contain that passed information as a string, is there a way or method to do this?
Seems like you've understood form action incorrectly.
Action defines which code will handle your form values, and not which page will the results be pasted into.
you'll want main.js to receive the form results and handle them in a way to be pasted into a results.txt file for example. But allowing a user of your website to create or edit files on your server is insecure.
The only option i think of, unless you have access to server side coding, like php or asp, is sending the submitted form information to your email using mailto:
<!DOCTYPE html>
<html>
<body>
<h2>Send e-mail to someone#example.com:</h2>
<form action="MAILTO:someone#example.com" method="post" enctype="text/plain">
Name:<br>
<input type="text" name="name" value="your name"><br>
E-mail:<br>
<input type="text" name="mail" value="your email"><br>
Comment:<br>
<input type="text" name="comment" value="your comment" size="50"><br><br>
<input type="submit" value="Send">
<input type="reset" value="Reset">
</form>
</body>
</html>
can you run asp or php?
Following could be the part of your javascript file.. If you are not going to include any JS file then you can use it directly.
function checkAge() {
var x = document.forms["Form1"]["Age"].value;
if (x == null || x == "") {
alert("Age is empty");
return false;
}
else
alert(x);
}
Then your form should looks like
<form name="Form1" action="abc.jsp" onsubmit="return checkAge()" method="post">
Age: <input type="text" name="Age">
<input type="submit" value="Submit">
</form>
Cross check with your form and see what went wrong..

How to link another page using button? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have used a template from the web for a Login page, and I am not able to figure out how can I link this page to another when one clicks the 'Login' button. I have no knowledge of HTML and CSS or JS , so if anybody can guide me through this I'll be grateful.Its for a college project that has to be submitted tomorrow. Its not that I don't want to learn, but there was something else I was working on which didn't work out pretty well so I had to start this and I have only a day.
I was unable to paste the code here. SO here's the link : http://pastebin.com/pPS0Np8A
<input type="button" value="click" onclick="window.open("http://www.google.com/"); window.open("http://www.youtube.com/");" />
If it's just a Link when pressing the button, put an <a>-tag around your button and the LInk inside the href attribute:
<p><input type="submit" value="Sign In"></p>
using harshit's solution i added the id to restore css properties but if the css value is a class rather than an id just replace id= with class=.
<input type="button" value="click" id="myCssClassId" onclick="window.open("http://www.google.com/"); window.open("http://www.youtube.com/");" />
So you were "not able to figure out how can I link this page to another when one clicks the 'Login' button".
Simplified from the login-page you provided, you have the following code:
<form action="Default5.aspx" method="POST">
<fieldset>
<p><label for="email">E-mail address</label></p>
<p><input type="email"
id="email"
value="mail#address.com"
required="required" />
</p>
<p><label for="password">Password</label></p>
<p><input type="password"
id="password"
value="password" />
</p>
<p><input type="submit" value="Login" /></p>
</fieldset>
</form>
Now, note the <input type="submit" value="Login" />. Once you'll click that, the form will submit the data contained in it (the password and email).
When you submit a form, the form needs an address where it needs to send the data to. This is then also the page that is displayed ('redirected'). You set this simply with the form's action attribute, which is just an URL.
Just wanted to rectify this for future readers.
EDIT:
So, for example an exact image-search on google could work like:
<form method="GET"
action="http://www.google.com/search"
target="_BLANK"
onsubmit="var e = this.getElementsByTagName('input');
e[1].value= 'isz:ex,iszw:' + e[3].value
+ ',iszh:' + e[4].value;
return true;
"
><fieldset>
<input type="hidden" name="tbm" value="isch" />
<input type="hidden" id="tbs" name="tbs" />
<p>Search Image:
<input type="text" name="q" value="search" />
</p>
<p>
Width: <input type="text" value="32" /> px <br />
Height: <input type="text" value="32" /> px <br />
<input type="submit" value="Search" />
</p>
</fieldset>
</form>
Example jsFiddle here
Here the method is changed from POST to GET. That way the values entered in the form are appended to the URL (so anyone can read them).
To close with a final example of how to open a new blank page I added the target-attribute, and pointed it to _BLANK.
The example's are intentionally kept simple, style and expand on them as you wish.

Categories

Resources