How to send data via HTML - html

Hi I need send actual time via html, like: /time_12:12_1.1.2018 on action on button or automatic. I have codes but I donĀ“t know how to connect it.
TIME:
<script>
document.getElementById("demo").innerHTML = Date();
</script>
Sending data:
<form action="/">PWM:
<input name="PWM" value="50" type="text"><input value="Submit" type="submit"></form>
Any ideas?

you want to submit the date as form data, or as part of the uri?
As form data
<form action='/' method='POST'>
<input type='hidden' id='time' value='' />
<input type='submit' value='Submit' />
</form>
<script type='text/javascript'>
document.getElementById('time').value = Date();
</script>
As URI
<form id='timeForm' action='' method='POST'>
<input type='submit' value='Submit' />
</form>
<script type='text/javascript'>
document.getElementById('timeForm').action = '/'+Date();
</script>

Related

How to fix recaptcha error?

I have a sitekey and I want to reproduce the captcha locally. However, when I open the html it says invalid domain for sitekey.
this is the code in my html file:
<script type='text/javascript' src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<form method="post" action="you cannot see this link">
<input type="text" placeholder="productcode_size" name="pid">
<input type="text" placeholder="productcode" name="masterPid">
<input type="hidden" value="1" name="Quantity">
<input type="hidden" value="" name="x-PrdRtt" id="captcha_val">
<input type="hidden" value="Add To Bag overlay" name="layer">
<input type="hidden" name="ajax" value="true">
<br>
<br>
<br>
<br>
<div style="opacity: 0.3" class="g-recaptcha" data-sitekey="you cannot see this sitekey"></div>
<br>
<div class="contionue-shopping-wrapper">
<form class="co-formcontinueshopping" action="You cannot see this link" method="post" id="dwfrm_cart_d0ffhvzsobkp">
<fieldset>
<button class="rbk-button-red button-primary bp-black right" type="submit" value="Continue Shopping" name="dwfrm_cart_continueShopping">
<span>Continue Shopping</span>
</button>
</fieldset>
</form>
</div>
</form>
<script>
check = setInterval(function() {
v = document.getElementById('g-recaptcha-response').value
if (v.length > 0) {
var r = '&x-PrdRtt='+v+'"">ATC Link</a>';
document.getElementById('captcha_val').value = v
var sz = document.getElementById('sz').value;
var pid = '?ajax=true&pid='+sz;
document.getElementById('hack').innerHTML = '<a href="'+document.forms[0].action+pid+r;
clearInterval(check);
}
}, 400)
</script>
</body>
</html>
Please can someone help me fix this? I want to be able to complete the captcha locally to extract the captcha response.
According to this page https://developers.google.com/recaptcha/docs/start
If you would like to use "localhost" for development,
you must add it to the list of domains.
so simply add "localhost" (or "127.0.0.1") , that should work for you.

add parameters to form url before submit

I need to add a path to a file to the form url before submitting. I created therefore a text field and want to add the text to the url without php.
can somebody help?
the existing code:
<form action="http://127.0.0.1:8080/WebService1/HTTPMethod_1?new_value=value" method="post">
<input type="text" value="" size="30" name="filename">
<input type="submit" name="submit" value="Submit" class="continue-button">
</form>
look into using hidden input fields. these allow you to send form data, but not necessarily show a form field.
for instance:
<script type="text/javascript">
function setFormAction() {
document.myForm.action = document.getElementById("url").value;
}
</script>
<form name="myForm" method="POST" action="default.php">
<input type="value" name="url" id="url" />
<input type="submit" name="submit" onclick="setFormAction();" />
</form>

Create HTML page with two submit buttons

I have the next HTML code:
<!DOCTYPE><html><body>
<form method='post' action='/upload' enctype='multipart/form-data'>
<input type='file' name='uploadFile'/>
<input type='submit' /></form>
</body></html>
Which create a file input and submit button, which sends a POST method (/upload).
I want to create a new button (submitBig), which would send another POST method (/uploadBig).
How can I do it?
A simple workaround, Create 2 Forms:
<!DOCTYPE><html><body>
<form method='post' action='/upload' enctype='multipart/form-data'>
<input type='file' name='uploadFile'/>
<input type='submit' /></form>
<form method='post' action='/uploadBig' enctype='multipart/form-data'>
<input type='file' name='uploadFileBig'/>
<input type='submit' /></form>
</body></html>
Else you should indeed refer to Javascript.
Use JavaScript to run a different function for each button. Set the .action and do the .submit from there.
You will need to use Javascript. Essentially this will edit the Action of the form and post it on click:
$('#big-submit').click(function(e) {
e.preventDefault();
$(this).closest('form').attr('action', '/uploadBig').submit();
});
An even better solution would be to just have the one button, and then get the file size on click and post to the relevant action.
You can use jQuery or simple Javascript:
<!DOCTYPE>
<html>
<body>
<form method="post" id="theForm" action="/upload" enctype="multipart/form-data">
<input type="file" name="uploadFile" />
<input type="submit" value="normal Submit (/upload)" />
<input type="button" id="bigButton" value="big Submit (/uploadBig)" />
</form>
<script type="text/javascript">
var theForm = document.getElementById('theForm');
/* When the button is clicked */
document.getElementById('bigButton').onclick = function() {
/* Change the location */
theForm.action = '/uploadBig';
/* Submit the form */
theForm.submit();
};
</script>
</body>
</html>
You can use the HTML5 formaction attribute to do that (but you have to check it's compatibility with your requirements to use it : it only works on recent browsers).
<!DOCTYPE html>
<html>
<body>
<form method="post" action="/upload" enctype="multipart/form-data">
<input type="file" name="uploadFile"/>
<input type="submit" value="Submit" />
<input type="submit" value="Submit big" formaction="/uploadBig" />
</form>
</body>
</html>
Here One way to get around this is to handle each button's OnClick event and set the "action" for the form dynamically:
<!-- create the form -->
<form name="Form1" method="post">
<!-- Add the data entry bits -->
Your Name <input type="text" name="text1" size="10" /><br />
<!-- Add some buttons -->
<INPUT type="button" value="Button1" name=button1 onclick="return OnButton1();">
<INPUT type="button" value="Button2" name=button2 onclick="return OnButton2();">
<!-- close the form -->
</form>
Our button click handlers for Button1 and Button2 would look like the following:
<script language="Javascript">
<!--
function OnButton1()
{
document.Form1.action = "Page1.aspx"
document.Form1.target = "_blank"; // Open in a new window
document.Form1.submit(); // Submit the page
return true;
}
function OnButton2()
{
document.Form1.action = "Page2.aspx"
document.Form1.target = "_blank"; // Open in a new window
document.Form1.submit(); // Submit the page
return true;
}
-->
</script>
<noscript>You need Javascript enabled for this to work</noscript>
Where Page1.aspx should be called when Button1 is pressed, and Page2.aspx called when Button2 is pressed.

Problem in form submit through javascript

I am submitting form via javascript by using 'document.FormName.submit()' . But this is giving me error of 'submit is not a function'. I m using IE8
<script typr="text/javascript">
function submitForm()
{
document.theForm.submit()
}
</script>
<body>
<form name="theForm" method="post">
<input type="text" name= "name">
<input type="button" name="submit" value="submit" onclick="submitForm()">
</form>
</body>
Please help me ?
problem is with your button name
i have use this its work fine
<script type='text/javascript'>
function submitForm()
{
document.theForm.submit();
}
</script>
<form name="theForm" method="post" action="default.php">
<input type="text" name="t" id="t"/><br/>
<input type="button" name="t1" value="submit" onClick="submitForm();">
</form>
use
document.forms[index].submit()
instead
Try this:
document.getElementsByName("theForm")[0].submit();
And you need to put the script after you declared the elements so :
<form name="theForm" onSubmit= "submitForm()">
<input type="text" name= "name">
<input type="submit" name="submit" value="submit">
</form>
<script type="text/javascript">
function submitForm()
{
document.getElementsByName("theForm")[0].submit();
}
</script>
Or you can use events like document onload if you want to kepp your scripts in the page head.
If your form name is FormName
try this
Action
by the way your code is missing a semicolon at the end of the statement
and a spelling mistake here
<script typr="text/javascript">
typr
Here is the problem
change it typr is nothing should be type
<script typr="text/javascript">
to
<script language="javascript">
OR
<script type="text/javascript">
I just copy your code and executed in IE8 and it worked fine, so how is not working on your IE8. May be it is because of your hierarchy. So you please give id to form and try document.getElementById to access your form and then submit method. Do some thing like this"
<script type='text/javascript'>
function submitForm()
{
document.getElementById('your_form').submit();
}
</script>
<form name="theForm" id="your_form" method="post" action="default.php">
<input type="text" name="t" id="t"/>
<input type="button" name="t1" value="submit" onClick="submitForm();">
</form>
document.getElementById("theForm").submit();
It works perfect in my case.
you can use it in function also like,
function submitForm()
{
document.getElementById("theForm").submit();
}
Set "theForm" as your form ID. It's done.

html javascript type=file

With a html type=file, how can I validate to determine if a file was uploaded, (for client side validation using javascript or jquery)
<form action="program" enctype="multipart/form-data" method="post">
<input type="text" name="textline" size="30">
<input type="file" name="datafile">
<input type="submit" value="Send">
</form>
<script>
if (something )
message = "You did not upload a file...";
</script>
Same way as any other input, look at the value. For example
<form id="programform" action="program" enctype=...
<script type="text/javascript">
document.getElementById('programform').onsubmit= function() {
if (this.elements.textline.value==='')
alert('Please enter a description.');
if (this.elements.datafile.value==='')
alert('Please choose a file to upload.');
else
return true;
return false;
}
</script>
Thanks for the push in the right direction... Here is what I was looking for.
<form name="registration_2" id="registration_b" action="registration_b.php" method="post" nctype="multipart/form-data" accept-charset="UTF-8" onsubmit="return check_checkboxes();">
<input type="text" name="textline" id="textline" size="30">
<input type="file" name="datafile" id="school_logo_id">
<input name="no_school_logo_id" id="no_school_logo_id" type="checkbox" onclick="no_school_logo(this);"/>Our school does not have a logo
<input type="submit" value="Send">
</form>
<script type="text/javascript">
function check_checkboxes()
{
var logo = document.getElementById('school_logo_id');
var nologo = document.getElementById('no_school_logo_id');
if (logo.value==='' && nologo.checked===false)
alert('Must enter logo file or check no file available.');
}
</script>