Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

retriving checkbox values

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to display a list of users with checkbox in its front. I now want to select some of the names and delete it in database. I have written code to display users. I don't know how to get the selected values and delete it. Please help me here is what I have tried


The code above displays list of names along with checkboxes. But returns value "user" and not the name in database. Also if I uncheck a name it again returns user.



 
Author
Posts: 26
MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without actually running the code, it looks to me like you've got too much inside of the central for loop, so that it generates something like:

<html>
<body>
<form>
<input ... value='User' name='user' />Tom</input>
</form>
</body>
</html>
<html>
<body>
<form>
<input ... value='User[i]' name='user' />Dick</input>
</form>
</body>
</html>
<html>
<body>
<form>
<input ... value='User[i]' name='user' />Harry</input>
</form>
</body>
</html>


and so on. This is clearly wrong.

An HTML document should have only one html element and only one body element. Anything else is undefined. Note that input elements do not have closing tags, but that doesn't matter here because there's no connection between the checkbox input elements and the form that contains the submit buttons. You should add a input statement to that form, something like:

<input type="hidden" name="username" value="" />


Then, your checkboxes can look something like this (without the extra, html, body and form tags):

out.println("<input type='checkbox' value='"+User[i]+"' onclick='document.add.username.value+=this.value+\',\';' /> "+User[i]);

When a submit button is clicked, the hidden value should be a list of comma separated list of user names (possibly with duplicates) and a trailing comma.

Also note that, with the exception of radio buttons, input elements should have unique names. Yet, I don't see why there's a need to name the input statements at all in your code since the necessary info is passed by using the [i]this
variable.

hth - Larry

 
knowledge is the difference between drudgery and strategic action -- tiny ad
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic