HTML Form Submit pass array to PHP [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 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.

Related

Is there any way to create automatically check boxes in PHP? [closed]

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 1 year ago.
Improve this question
My plan is to automatically create checkboxes with names and random values for example a hundred in a for loop. Is there any way to do this?
And if i want to use these how to change the value and save it to the array?
in php
<?php
for($i=0;$i<100;$i++){
echo '<input type="checkbox">';
}
//if you want to add a submit btn at last
echo '<input type="submit" value="Submit">';
?>
It is the code to automatically create 100 checkboxes
And put your own values and styles

Input text from html to javascript [closed]

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.

Make what a user puts in an input box automatically appear in another box [closed]

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".

How to save date in html [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 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.

Dynamically add array textbox in a form [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
I need to add in all the textbox manually in my project.
<form>
<?php for($i=0;$i<3;$i++){ ?>
<input type="text" name="product[]">
<?php } ?>
</form>
how can i solve this problem so that the number of product for insert can be flexible.
For example, user1 need to purchase 4 item, user2 wan to purchase 8 item. wihtout dynamic textbox, i need to add the textbox manually by adjusting the looping value (in my coding).
It sounds like this is an update to customer products right?
if so, you probably have products array somewhere.
so you might do :
$products = $customer->products ;//or your array
for($i=0;$i<count($products);$i++){
// your code
}
or you can add it via javascript (sounds more like it if this is the purchase moment - new products, not update)
or you might want to have somewhere a config per customer.
or Please be more specific and more descriptive

Categories