A client needs a system in which their customers will be able to check the photos (displayed on a grid) and send an e-mail (via a form placed below the photo grid) with the photos' IDs.
The first alternative that came in mind was apply the onclick to get the photos' ID, but I have no idea how to send them to the form.
Quite easily, just run the onclick event to get the id which you store in variable and then replace the form input tag value with this value:
var id; // contains image id
$("input").val(id);
or if you have more input tags then add id attribute to them and change corespondingly the selector. And then you can fire the submit button to post the form data.
Or more advanced yet in this case more appropriate way is to send data with ajax without the need of any form.
Related
passwd
So I want to change it.
Use POST method instead of using input form.
(Passwd are posted from another program)
How to change it
Thanks!
enter image description here
Change the form into POST(Passwd is being sented from another program by post)
I have a Javascript calculator inside a form, that computes some simple Math formulas based on some values filled in the form and displays some results inside html tags with different IDs.
When clicking on SUBMIT button, an e-mail is sent with data that has been filled in the input fields and the computed results.
I have no problem regarding the standard form fields (input, select) but the computed values. Those values are in html tags with IDs, and I am trying to POST those IDs but I get nothing.
How can I read and send via POST to a mail function some texts and values that are modified on the fly by a javascript?
You have 3 options
1.Use JS for performing request. For example in jQuery you can do it like that:
$.post('/your-url', {some_value: $('#your-field-id').val()}, function (data) {
// some code after submitting
});
2.Add some hidden fields with proper names and fill them with JS.
The thing is that when you submitting form only inputs with name are sent.
$('#hidden_field_with_name').val($('#your-id').val());
3.If those values are filled by JS in fields like: input/textarea or another input fields you can just add name property to them and then you'll get it on server side.
You can read more about submitting forms here: https://www.w3schools.com/html/html_forms.asp
If you already know the id's of the elements you want, simply using getElementById you can get the content inside of it. eg:
var someText = document.getElementById('yourElementId').text
and depending on what do you want, you could use .text or .innerHTML
var someHtml = document.getElementById('yourElementId').innerHTML
I have a table for which I pull the data from database. In each cell there in an edit image so when user clicks on it, there will be a pop up message and he can edit the data in the cell.( By using prompt() method). So I want to update the database whenever the data in a cell is changed, can I use onchange event attribute for a cell of a table? something like:
<td onchange="myFunction()">
if not, what kind of event attributes should I use?
No. onchange (or rather the change event) is only used for input fields.
The proper way to do this is to let your JavaScript that prompts for input (using prompt is ugly btw, why not show a text field in the cell?) update both the cell's content and send the AJAX request to store the new value on the server.
I have a form (HTML) with some inputs (checkbox) and I want to submit only inputs that user has clicked ou unclicked and ignore the others inputs.
I'm thinking in add a class (javascript) to the input when user change value. But I don't know if it is a good ideia.
Any Suggestions?
You can have the form that submits onClick() and calls a Javascript. When that happens you then search what values have been unchecked and then use the Javascript to submit it to the next page to handle the response.
However not sure what you are trying to achieve doing this...
Class approach is working.
When user click on input I add class "envia":
$("INPUT[type='checkbox']").click(function(){
$(this).addClass("envia");
});
On submit I send only data with the class I want:
$.post("/financeiro/funcional/contasapagar.php", $(".envia").serialize(), function(data){
//code here
});
Only data the user changed is send to server.
My goal untill now is to fill a form with values from a table (html table).
it is a kind of refreshing the form.
so the user who wants to modify the html table through the form must prefill the form with values wich he already selected.
I used the DOM to acces to each row and cell in the table and i used ajax to pass parameter to other jsp.
but Iam confused what shall be the next step to fill the form.
Just get the input element from DOM and set its value attribute.
document.getElementById('inputId').value = 'newValue';