![]() |
Posting multiple checkbox values to <input type=text>
print "<Font face=\"calibri, Arial\"><table id=\"rnatable\" border=2px width=100%>";
print "<th></th>"; print "<th>a</th>"; print "<th>b</th>"; print "<th>c</th>"; print "<th>d</th>"; print "<th>e</th>"; print "<th>f</th>"; print "<th>g</th>"; while($array = mysql_fetch_array($sql_query)) { $id=$array['a']; print "<tr id=\"newtr\">"; print "<td><input id=\"check\" type=\"checkbox\" name=\"keyword[]\" value=\"$id\" ></td>"; print "<td>".$array['a']."</td>"; print "<td>".$array['b']."</td>"; print "<td>".$array['c']."</td>"; print "<td>".$array['d']."</td>"; print "<td>".$array['e']."</td>"; print "<td>".$array['f']."</td>"; print "<td> <a href=\"http://localhost/rnasearch/retrieve.php?a=$id\">bla</a> </td></tr></font>"; } print "</table>"; } this is part of a php searchengine script that i wrote to retrieve data from a database and as you can see the last column that is g contains a link which when clicked takes the user to the second php script which retrieves additional information of that entry, but this is done for only single entries so as you can see i introduced checkboxes so that the user can check any number of checkboxes and retrieve information as per their wish now to do this i created a <input type=text where i want the value of these checkboxes i.e. $id to be posted in a delimited format so that the user can then click the corresponding button and retrieve the information this is the code <div id="floatMenu"> <ul class="menu1"> <center><li><form name="senddata" method="POST" action="http://localhost/retrieve.php" style="display:inline;"><input id="fasta" type="text" class="multitext"><input name="Fasta" type="Submit" value="Retrieve Fasta"></form> this is a css floating menu....so far so good....everything went fine.... after this i had to write a javascript to do this and i've been stuck there searching forums for the last 4 days! this is the javascript i found from somewhere which came close to doing wht i wanted it to do window.onload = function () { var cb = document.getElementById('check'); var fasta = document.getElementById('fasta'); cb.onclick = function () {fasta.value = cb.value + ","; };}; this script only sends the value of the first checkbox in the table, the others are not found by it, mind you its not the first checkbox selected its the first checkbox that is present in the table how can i resolve this problem so that even if i have n number of checkboxes in my table, if the user chooses to do so they can retrieve n number of information....please help i've almost lost hope in this! |
You need to pass all the checkboxes to the server and then build the extra code onto the query there. There's no point doing anything with JavaScript as anything that you do in JavaScript would just replicate what you need server side for it to work for those with JavaScript turned off. JavaScript can only provide enhanced functioning for those with it enabled and in this situation there is nothing to enhance.
|
It's actually much easier to do this in the server in PHP code, anyway.
You just check to see if you got any values in $_GET["keyword"] and, if so, just convert all the values into an IN( ) list for your SQL query. I don't use PHP, but I *believe* it would be something like this: Code:
if ( isset($_GET["keyword"]) ) |
I'm actually a newbie, its been hardly 15 days i have been working on this, so the magnanimity of the problem is greater for me as i still haven't been have able to successfully construct url strings considering n number of possible combinations....i will incorporate a non javascript method in the future but right now javascripting seems the easiest way to go
|
Quote:
|
Quote:
|
| All times are GMT +1. The time now is 05:12 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.