Frank Vilea
Frank Vilea

Reputation: 8487

Accessing information outside an HTML form

At the beginning of my PHP page I have a form with a save (submit) button. Below I draw a list of items which are from the db. I now want the user to be able to tick the items he wants to select. My problem: All the information is outside my form. How can I access the generated information?

<form method="post" action="">
<input type="submit" name="save" class="inputButton" value="Save" />
</form>

PHP function below:

drawArticles($id, $option, $credit);

Contents of PHP function drawArticles():

..CONTENTS REDUCED..
echo        "<div class='groupsTickbox' name='".$aid."'><input type='checkbox'></div>";
echo        "<div class=\"divListGroups\">";
..CONTENTS REDUCED..

Upvotes: 0

Views: 159

Answers (4)

joakimdahlstrom
joakimdahlstrom

Reputation: 1595

Have a look at this; it shows you can access DOM information (arbitrary nodes in the document) using javascript

Upvotes: 0

BobGneu
BobGneu

Reputation: 1612

You can always save key information about their query in a session var and save it with the post, since the information is being displayed on the page. If it is a second form there are some very interesting tutorials on how to deal with multi page forms on the web:

Upvotes: 0

Tomasz Kowalczyk
Tomasz Kowalczyk

Reputation: 10467

You MUST insert all form elements in <form> tag if you want them to be automatically included in POST request. Otherwise, you'll need to manually code JavaScript onSubmit() handler to include values of those DOM nodes to the form request. You can surround whole page with <form> elements, if that matters.

Upvotes: 2

KOGI
KOGI

Reputation: 3989

You can either use Javascript's native DOM traversal mathods such as document.getElementById( ) and document.getElementsByTagName( ) to find the DOM elements you need, or you can use jQuery as follows: var tickbox = $('div.groupsTickbox');

If you do it this way, you will have to assign an onsubmit handler to the form and generate your own submission data. If you don't want to do this, then you have to put your elements inside the <form> tag.

If you're not already, you should look into jQuery purely for it's power in traversing the DOM (it has many other benefits as well)

Upvotes: 0

Related Questions