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

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.

Related

How can my html not read my js [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
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.

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.

Submitting a form without page reload [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I don't know Ajax or PHP but I want to submit this form without page refresh and also want to appear check icon beside the submit button. How can I do this?
<form id="form" action="" method="post">
<input type="text" id="email" value="e-mail address" />
<input type="submit" id="submit" name="submit" value="Submit" />
</form>
<script>
function xyz(){
var email_val=$('#email').val();
$.post("ajax.php",{"email":email_val},function(data){
if(data) {
$('#message').html('Data submit successfully');
$('#email').val('');
}
else{
$('#message').html('Failed');
}
});
}
</script>
<form id="form" action="" method="post" onsubmit="xyz()">
<input type="text" id="email" value="e-mail address" />
<input type="submit" id="submit" name="submit" value="Submit" />
<span id="message"></span>
</form>
ajax.php
if(isset($_REQUEST['email'])){
//Your code here
}
If you are not aware of AJAX and PHP but still you have to submit a form without page reload then follow this tutorial.. do some home works
http://net.tutsplus.com/tutorials/javascript-ajax/submit-a-form-without-page-refresh-using-jquery/

how to check html5 form validity with vanilla javascript? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
HTML:
<form id="myform" method="post">
<input name="email" type="email" required=""/>
<input name="fname" type="text" required="" />
<input name="zip" type="text" />
<input type="button" value="button" />
</form>
Here I want to just check email by applying javascript function for html5 can we do that?
Edit
It has been unclear/misunderstood before. My question is do we have boolean valid check like form.email.valid() so that we can do check for email only with using javascript?
You should change your button input. A HTML5 submit button needs to look like the following:
<button type="submit">Submit</button>
Also, giving your e-mail a placeholder would be nice:
<input name="email" type="email" placeholder="me#example.com" required=""/>
Example jsFiddle.

How to make my eBay search bar specific to my store? [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 3 years ago.
Improve this question
I have recently re-designed the look of my company's eBay store, and have put a custom search bar in place. However, when my user's search for a product, it is not searching for products in my store in particular. Instead, it is doing a general eBay search.
I have included my full code in a JSFiddle for you helpful people to check out, and would really appreciate it if anyone can tell me how to make it so it searches only for products in my store in particular.
Thanks in advance:
JS FIDDLE: http://jsfiddle.net/DanCUK89/U6LqJ/
<form name="search" method="get"
action="http://search.stores.ebay.com/search/search.dll?GetResult&">
<input type="text" name="query" maxlength="300" >
<input type="hidden" name="fcd" value="2">
<input type="hidden" name="from" value="R10">
<input type="hidden" name="sasel" value="<Your store number>">
<input name="submit" type="submit" value="Search">
<br />
<input type="checkbox" name="srchdesc" value="y">search titles & descriptions
</form>
or try this
<form name="search" method="get" action="http://search.stores.ebay.com/search/search.dll">
Search Our Store:
<input type="text" name="query" size="7">
<input type="submit" value="Go" width="20" height="16" border="0">
<input type="hidden" name="MfcISAPICommand" value="GetResult">
<input type="hidden" name="sid" value="ENTER STORE ID HERE">
<input type="hidden" name="store" value="ENTER STORE NAME HERE">
<input type="hidden" name="colorid" value="15">
<input type="hidden" name="fp" value="0">
<input type="hidden" name="srchdesc" value="y">
</form>
use:
"/your _store/_i.html
on form acion like this:
<form action="/your_store/_i.html">
your_store is the liunk to your store like this:
stores.ebay.com/your_store

Categories

Resources