Adding elements to a table from an input area - php

I am trying to have something like the image below in my PHP page.
(The links are in the comments. I was unable to post them here properly)
Once I enter the keyword and hit the "plus" it should appear in the table, along with the color to the right. The sequence of colors will be predetermined. If I enter a keyword again and hit the "plus" again, the keyword should appear just below the earlier keyword int the table. For the time being I am assuming the table consists of 5 rows and there are less than or equal to 5 keywords.
Also I want to have a submit button at the bottom that when clicked should send all the keywords now present to a PHP file. I have a form with the action attribute set to a PHP file. The table and the keyword input field are to be a part of a form.
I prefer using javascript and not PHP for many complications. Is there a way I can store all the keywords and then send it to the PHP file once the form is submitted?
Any help would be greatly appreciated.

You could:
Build the html form with five text inputs, all stacked on top of one
another (I think using position: absolute).
Place html table underneath inputs.
Place submit button underneath table.
Use javascript to:
hide the four text inputs that aren't currently being used
display the text input and corresponding color in the table when the user presses the +.
hide the current text input and show the next input when the user presses the +.
When user hits submit button, all five input values will be submitted to action='*.php'

Related

Fetching value from codeigniter form field among input fields of same name

I don't need any code, I just need the right way to do it.
What I am doing?
Here is the thing. I am making a software for a pharmacy (Drug Store). I have created a tab for shortlist for the drug. See the picture.
enter image description here
What problem I am facing?
In the last column, I have a form field to input drug or add stock. But you can see there are many form fields for so many rows. When I click to "Confirm" button, it's not gonna work cause the table has been generated using loop. So, for all the fields there are same name.
How can I take the value of input field right above the submit button. I mean when I click confirm button it will take same row's input field not others.
How can I do it? No code needed. I am using php codeigniter framework.
Thanks
create one variable like '$i' and increase it and append it on last of input name.as well as give id to submit button and append id with $i.
for eg. name_1,name_2,submit_2,submit_2
when you submit just get the id of submit button. Then get the number from id eg.2,3.take input from the same input variable id. You can do it using ajax. So it will be done without refresh page.

Read write categories from form

I have low hopes of somebody actually answering that cause of the high level of spoon feeding involved ;-) But then again, I ll give it a shot.
I would like to make a simple form consisting of an input text field, a dropdown list of existing categories and a submit button. The logic would be:
Case 1: User inputs text to the input field and clicks submit. Then code checks if text equals name of existing category. If category name exists then nothing is done and code prompts user that this category exists. If category name does not exist then the entered text is being written in the database as a new category.
Case 2: User leaves input field empty and selects a category from dropdown list of existing categories. Then upon clicking submit, the code would store the category name selected from the dropdown in a variable.
Case 3: User clicks submit without entering any text or selecting any category from dropdown, then code does nothing and prompts for user to retry..
Any help, code or link, would be much appreciated.
Harry
What you are talking about is a relatively easy task. Even when you are new to programming, this should be possible. What you want is a form validation.
I would recommend to call a function on submit like that:
onsubmit='checkForm()'
Put this code in your form tag.
In that function you can check what ever you want to make sure that the form works the way you want it.
You should read this:
http://www.w3schools.com/js/js_form_validation.asp

Insert content from another site's table into my form using AJAX/PHP?

My question begins below this paragraph: I have a form containing an input where someone can enter a permit number (i.e. '121640466') and once an adjacent button is clicked, a new browser tab takes you to a site that contains all of that permit's information in a tabular format:
$(".bis_button").click(function() {
var inputValue = $(this).parent('.frm_form_field').find('input').val();
window.open('http://a810-bisweb.nyc.gov/bisweb/JobsQueryByNumberServlet?passjobnumber='+inputValue+'&passdocnumber=&go10=+GO+&requestid=0');
});
Now, my question has several components to it that I'm hoping can help someone point me in the direction of what I'm looking to achieve:
What I essentially want is to allow someone to enter a permit number, and once an adjacent link is clicked, multiple specific fields in my form are populated with specific content from the site containing the table.
Let's use this page (we'll call it "permit page") that contains a permit's information to show what the process would look like. For this example, let's extract the Borough (Manhattan) from the table w/ heading Location Information (Filed At):
On my form, enter permit number 121640466 into <input id="field_cao2yl">
On "permit page", Find <table> that contains <td> w/ content "Borough" and copy the content of the next adjacent <td> (in this case, the content is "Manhattan")
On my form, insert "Manhattan" into <input id="field_qeu829">
I'm hoping that this can be done with AJAX and PHP so that the page doesn't have to be refreshed to have the information from "permit page" inserted into my form's inputs.
Here's how I'd do it:
Accept the input from the user in your page
Pass it to a PHP script using AJAX and retrieve the value in your PHP script
Parse the required information using an HTML parser like SimpleHTMLDOM.
Send back the results to client
Populate your form fields with the values.

How to capture multiple values in 1 input field (a la Facebook messages)?

The main example would be Facebook Messages. On the "To:" field, you can type in one letter, then it will show a search result of your friends that matches that letter. Then once you choose that friend, you can add another friend, on that same input field.
Is there a function/script that allows you to add more than 1 data on the same input field?
Is there a function/script that allows
you to add more than 1 data on the
same input field?
Short answer, no.
If you look at the source code for the "To:" field, you realize Facebook isn't achieving this effect with only a text input.
This trick uses a div to mimic a text input, but also has a text input (with no border) within it to capture the text being typed. Once they a match is found in the search drop down, a 'token' is inserted into the div, and the text input is shifted over.

Getting the value of dynamically created text box in PHP

I have a link. Whenever it is clicked, a new page will be displayed which contains data such as id, name, price and a select option with a check box. This page also contains a button. All these details (id, name, price) are fetched from a table. If the check box is checked and the button is clicked, a new page with the selected values along with a text box for each id should be displayed. If a value is entered in those text boxes and the button is clicked, I should fetch the value of the text box. I have given the text box the name id (which is retrieved from the table).
I assume the new text box is created using javascript. Give it a fixed name attribute that your PHP script knows and read it from _POST[]
Well, there are two ways of doing this.
Name your text boxes as an array. So the name would be name[] or name[2]. Then, in PHP just loop over $_POST['name'] which will be an array (or empty if no text boxes were added). That way, you only need to submit the data that exists...
The other way would be to use Javascript to do the submission. You'd need to assemble the response into a common format (JSON perhaps) and then send that to the server...
But it's definitely possible...
You can use a naming convention for the name property of the textboxes that append an integer value to the end of the whatever generic name you use. Store the number of textboxes created and once the page is posted, you can reconstruct the name of the textboxes with a loop and read the posted values.

Categories