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 8 years ago.
Improve this question
i am new to html and php. i am trying to calculate difference between two dates. although i have managed to make a JS function for calculation the difference. but it need two date variables to calculate the difference.
i have use <input type="date"> to make an input of date from user. but now the problem i am facing is that how can i store the vale in the textbox(the date in it) into a variable ?
is there any $_POST method to get the date stored into a variable ?
Use an event Javascript and pass the new value parameter.
HTML:
<input type="date" name="dateOne" value="" onChange="setDate(this.value);"/>
Javascript:
var date;
function setDate(val) {
date = val;
}
Edit (based on comment)
For set the variable into a form, create an input type hidden (or other).
<input id="jsValue" type="hidden" name="jsValue" value="" />
In Javascript put the value into your input
document.getElementById("jsValue").value = yourVariable;
To see a result in your web page, create a span tag (or other)
<span id="seeYourVariable"></span>
In Javascript use the property innerHtml to put your variable into the tag
document.getElementById("seeYourVariable").innerHTML = yourVariable;
Use a hidden field to store the value of the variable and you will get the value using $_POST.
Related
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
I have got the following code:
<form method='POST' onsubmit='javascript:searchAndUpdateGrid(GET_THE_VALUE_OF_INPUT);return false;'
<input type="text" id="inputField" class="form-control" placeholder="Type something...">
</form>
I want to launch the function searchAndUpdateGrid with the value entered by the user in the input field. How can I do that ? (I would like to avoid to get it from Javascript)
Thanks !
Take it easy. You must write some javascript code for onkeyup event to doing that.
$(document).on('keyup','#inputField',function(){
searchAndUpdateGrid();
});
function searchAndUpdateGrid(){
var inputtxt = $('#inputField').val();
$.post('file.php',{text:inputtxt},function(data){
//type statement for after success the server request.
//Example you must put the result of destination file in to the
//HTML div that we assume it's id 'preview' then
//you should be type that code
$('#preview').append(data);
});
}
It will working fine.....
This is Jquery AJAX post method. But you can use GET method. If you using get method then you should change $.post to $.get. Another problum is what is inside the curly brackets?This is the parameter of you hoping to send textbox values to destination php or asp file.It might send your textbox values as text parameter.
$("#inputField").val() would give you the value of the input (with the help of jQuery). You are using javascript and looking for a javascript function - so there is no way to not get it from javascript. alternatively you can use PHP and get the value from the file that gets the form (the one specified in the 'action' attribute) with $_POST['inputName']
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 years ago.
Improve this question
I don't understand how to make and use forms. Can someone give me and example using external java script where there is an input text and a submit button and when it gets click it does a java script function. I also have some questions. If i'm not using a form to change pages do i need a method. What do i put for the action attribute. Are forms the best way to get input text data to java script. And why should i use a form and not just input tags.
Thanks.
No, you don't need a form to collect user input form fields.
Here is a really simple friendly example using MagJS:
HTML:
<div id="hello">
<label>Name:</label>
<input name="hello" placeholder="Enter a name here" />
<hr/>
<h1>Hello <name/></h1>
</div>
JS:
mag.module("hello", {
view: function(state) {
state.input = {
_oninput: function() {
state.name = this.value
}
}
}
})
Here is a link to the working example: http://jsbin.com/fivaqoliqe/1/edit?html,js,output
Hope that helps!
The short of it is that W3Schools lets you play around but they are scarce on explanation so I suggest you check out this resource instead (which also has a demo of a form): https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form
The action attribute is where it should go after it is done to further process the form (typically a route or backend server is where you will go after). Given what you have been talking about however, you only have one field and one button, so you should look into the onclick attribute and then look up the input field and read the value. You use a form when you have a lot of inputs that are related and should be sent at once. There's a lot out there though as this is very basic but if you have any questions just ask.
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 8 years ago.
Improve this question
I have a simple HTML where you can click images. These images, whence clicked will moved to the Top Nav bar, I have IDs from this images and able to get each of them using jquery/javascript. I have this IDs set to an array variable.
My questions, is there a way to pass this to the Form then I issue a Submit so I can process the arrays. It is a 1D array with just IDs.
You can use hidden inputs:
<input type="hidden" name="image_ids[]" value="1">
<input type="hidden" name="image_ids[]" value="2">
<input type="hidden" name="image_ids[]" value="3">
Just create a new hidden input for each image id, with the same name image_ids[].
Note that when you append [] to the name of various input fields, these values are submitted as an array, in this case named image_ids.
Another solution is just to concatenate all the IDs with a comma: "1,2,3,4,5" and send it in just one hidden input field (instead of a bunch of hidden input fields), then in your server script (assuming you're using PHP) you can convert the string "1,2,3,4,5" to an array using something like: $image_ids = explode(',', $_POST['image_ids']);.
Good look.
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 8 years ago.
Improve this question
I have a three input fields. I am trying to do a basic equation with the three inputs and have the result appear into another box. I do not understand how to make the result appear in that box. Any help please?
<input type="text" id="miles" placeholder="miles">
<input type="text" id="minutes" placeholder="minutes">
<input type="text" id="tip" placeholder="tip">
<input type="output" value="total" id='total'>
Since your tag is javascript, i assume your looking for an jquery/js solution.
I will give you an jquery solution:
First of all you have 3 input fields. I assume these are fields for calculating something.
With jQuery it could be done like this.
It checks if input field 1 or input field 2 has been changed. If there has been a change it will execute the function and give input field 3 the value of the other 2 combined.
$('.field1, .field2').change(function () {
var valfield1 = $('.field1').val();
var valfield2 = $('.field2').val();
var valfield3 = valfield1 + valfield2;
$('field3').val(valfield3);
});
You could even make this live editing, by replacing "change" with "keyup".
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
In my code (HTML and JS), I have a form with two fields; field A and field B. I want to write the JS code that will get the data from field A and use it to set the default value for field B. Can someone help me do that?
If you decompose the problem into smaller pieces, there appear to be three components:
Get value from Field A
Set value of Field B
Trigger the event
Let's start with the first one...
There are lots of ways to reference an element. Let's assume for a moment that your element has an id:
<input type="text" id="fieldA" />
Given that, we can get its value:
var valueOfFieldA = document.getElementById('fieldA').value;
Now that we have the value, let's move on to the second component...
Similar to above, all we have to do is reference the element. Once we have that, we can set its .value property just as easily as we can read it. Let's assume another id in the markup:
<input type="text" id="fieldB" />
Given that, we can set its value:
document.getElementById('fieldB').value = valueOfFieldA;
Finally, we want to trigger this. Should it be when a button is pressed? When something else happens? For now I'm going to assume it should be when the value of Field A changes, so let's attach the code to the event handler for the change event of Field A:
document.getElementById('fieldA').onchange = function () {
var valueOfFieldA = document.getElementById('fieldA').value;
document.getElementById('fieldB').value = valueOfFieldA;
};
Assuming that the elements exist at the time this code runs and that it's able to find them by their id properties, this final result should assign a function to the change event of Field A such that whenever its value changes the value is then set to Field B.