I have basic js script but i cant figure out why is it now working.
User write amout here:
<input class="dpinput" id="gvfrom" placeholder="Suma.." type="text" value="">
And change value in this form by submiting button in same form
<form>
<input type="hidden" name="amount" id="gvhere" value="">
<input type="submit" class="pbutt2" value="⇨" onclick="go3(); return false;">
</form>
JS script is here
<script>
function go3() {
var gvfrom = document.getElementById('gvfrom').value;
document.getElementById('gvhere').value = gvfrom;
};
</script>
Problem is that form is not submitted (normally is redirected to other site with values). Thanks for any help.
Just remove "return false;" from submit button.
Why would you put return false? Try removing it, it will work much better I guess.
Related
I am attempting to create a form on the page that requires the user to input text. Once the form is submitted, the user will then be redirected to the page assigned to it. My question is where am I going wrong and how should I resolve this issue? Could someone include a JSFiddle or Codepen.io pen for deminstration purposes?
For example:
User enters and submits "123456"
User is then redirected to the page www.domain.com/123456
I am assuming it is something like this:
HTML
<form>
<input id="projectid" maxlength="6">
<input onclick="findProject()" type="submit" value="Go">
</form>
Javascript
function findProject(){
document.location = document.getElementById('projectId').value();
}
I have included my own pen: http://codepen.io/ShaneHicks/pen/eZbbLz
Put a / before the url fragment
document.location = '/' + document.getElementById('projectId').value;
<form>
<input id="projectId" maxlength="6">
<input onclick="return findProject()" type="submit" value="Go">
</form>
<script>
function findProject(){
window.location = document.getElementById("projectId").value;
return false;
}
</script>
I have a HTML submit button and am trying to send hidden info to an outside form.
<form name="input" action="https://www.skinnybodycare.com/aff/join" method="post">
<input type="hidden" value="2skinnyme" name="enroller" />
<input type="hidden" value="Continue">
<input type="submit" value="Order Now">
</form>
And it has to take the user to https://www.skinnybodycare.com/aff/join and input the value and click on Continue... but can't figure it out and I'm against time here... help is very much appreciated...
I also want to say that I've already searched the forum for similar issues but couldn't find anything
The answer is: You can't pre-fill forms from outside, unless you've made code that reads values from the URL.
Here's some sample code (untested) to give you an idea of how to make the page work this way:
<form name="input" action="https://www.skinnybodycare.com/aff/join" method="post" **id="myform1"**>
<input type="hidden" value="2skinnyme" name="enroller" />
<input type="hidden" value="Continue">
<input type="submit" value="Order Now">
</form>
<script type="text/javascript">
var myvar = location.toString().replace(/[&?]2skinnyme=([^&]*)/, '$1');
document.getElementById('myform1').2skinnyme = myvar;
document.getElementById('myform1').submit();
</script>
Alternatively, you can just submit directly, from the original page, to the URL using AJAX and jquery, but that would require you to be on the same domain:
<script type="text/javascript">
$.post('https://www.skinnybodycare.com/aff/join', { enroller: '2skinnyme' }, function() {
alert('Form has been submitted');
});
</script>
I have two files. One is login.html which is a simple html5 file with a form.
HTML
<form method="post" action="" name="form1">entre the pasword:
<input type="password" name="code" placeholder="code" maxlength="6">
<p class="submit">
<input type="submit" name="commit" value="send" onclick="verif(document.form1.code)">
</p>
</form>
Second is my javascript file with the below code:
function verif(inputtxt) {
var pwd = "123456";
if (inputtxt.value.match(pwd)) {
window.location.href = 'Test.html';
} else {
alert('Code erron\351 ! ')
return false;
}
}
Now my problem is that when I enter my password, if it is wrong the alert message indicating an error should appear (it appears and I don't have a problem with that) and if it is correct, I should get redirected to the next page. The second part doesn't work for me.
Please help, I'm stuck with that for two days now..
Since your button is a submit button, I think it is submitting the form after the JS is done and this could be the reason why you don't get redirected to Test.html (as form action attribute doesn't have any value.) Try the below code for the HTML form and check if this solves the issue.
<form method="post" action="" name="form1" onsubmit="verif(document.form1.code);return false;">entre the pasword:
<input type="password" name="code" placeholder="code" maxlength="6">
<p class="submit">
<input type="submit" name="commit" value="send">
</p>
</form>
The return false; in the onsubmit attribute prevents the form's default submit action. The verif(document.form1.code) will be executed whenever the form is submitted (that is the submit button is clicked).
I'm trying to create a form which submits a string to another page only with the parameter name removed from the URL.
i.e. submitting the following form with "foo"
<form action="search.asp" method="get">
<input type="text" name="keyword" id="keyword">
<input type="submit" value="Go">
</form>
will go to search.asp?foo NOT search.asp?keyword=foo
Can this be done with pure html?
I guess this can be done with javascript and/or jquery but I'm not certain exactly how.
Can anybody help?
I'm a bit of a noob so a copy and paste solution would be great for me.
Update:
Thanks for the answers so far but they don't seem to be working. Perhaps a better way to do this is to get JQuery to construct the URL and load that URL? Any more suggestions would be great.
or maybe...?
$('input[type="text"]').blur(function() {
$('form').attr('action', 'search.asp?' + $('input').val());
});
Let's give the form and the submit button a classname for convenience and assume we have jQuery on the page.
<form action="search.asp" method="get" class="search_form">
<input type="text" name="keyword" id="keyword">
<input type="submit" value="Go" class="search_button">
</form>
<script type="text/javascript">
$(function(){
var $form = $(".search_form");
// save the default action, because we are going to mess with it.
$form.data("original-action", $form.attr("action"));
// listen to the click on the button, update the form action and submit the form manually
$(".search_button").click(function(){
$form.attr("action", $form.data("original-action") + "?" + $("#keyword").val());
$form.submit();
return false;
});
});
</script>
Not tested, but should work. Let me know.
Btw, saving the default action is maybe not needed. But just in case that you ever want to submit it with ajax without reloading the page.
Try this:
<form action="search.asp?foo">
<script>
$(document).ready(function(){
$("#btnSubmit").click(function(){
var keywordVal = $("#keyword").val();
window.location.href = "search.asp?" + keywordVal;
});
});
</script>
<input id="keyword" type="text" name="keyword">
<button id="btnSubmit">Submit</button>
I have written following function which checks whether start_date field is not empty and displays proper message when submit button is clicked. But then it takes the control to the previous page. So user has to write again all other fields on that form.
Is there any way to stay on that page even after prompting the error message, with all other fields value.
//JavaScript
function checkform() {
if(document.frmMr.start_date.value == "") {
alert("please enter start_date");
return false;
} else {
document.frmMr.submit();
}
}
// HTML
<html>
<form name=frmMr action="page1.jsp">
Enter Start date:
<input type="text" size="15" name="start_date" id="start_date">
<input type="submit" name="continue" value="submit" onClick="checkform();">
</form>
</html>
Thanks in advance
While you have a return value in checkform, it isn't being used anywhere - try using onclick="return checkform()" instead.
You may want to considering replacing this method with onsubmit="return checkform()" in the form tag instead, though both will work for clicking the button.
You can simply make the start_date required using
<input type="submit" value="Submit" required />
You don't even need the checkform() then.
Thanks
use return before calling the function, while you click the submit button, two events(form posting as you used submit button and function call for onclick) will happen, to prevent form posting you have to return false, you have did it, also you have to specify the return i.e, to expect a value from the function,
this is a code:
input type="submit" name="continue" value="submit" onClick="**return** checkform();"
Don't know for sure, but it sounds like it is still submitting. I quick solution would be to change your (guessing at your code here):
<input type="submit" value="Submit" onclick="checkform()">
to a button:
<input type="button" value="Submit" onclick="checkform()">
That way your form still gets submitted (from the else part of your checkform()) and it shouldn't be reloading the page.
There are other, perhaps better, ways of handling it but this works in the mean time.