Results 1 to 6 of 6

Thread: Check radio box (while loop problem)

  1. #1
    Join Date
    Mar 2012

    Check radio box (while loop problem)

    Hi guys.

    I have a PHP query that displays a response from my database in a while loop. What I have done is list several checkboxes that then gives additional data when selected and POSTed. The problem I am having is resolving a way to keep the checkbox in the checked state once it has been selected. As this is done in a loop I can't specify which name 'should' be checked.

    I'm probably not making an ounce of sense. See the images below.

    Attachment 14708

    Attachment 14709

    Thanks in advance!

  2. #2
    Join Date
    Mar 2012
    I can't understand (I'm a poor italian who knows just a little bit of English...) if you need to reload the form after it has been posted or what.

    When do you want the check has to been checked?
    After you submit the form end you reload it or during the form construction with the database data?

    That's important to me to help you.

  3. #3
    Join Date
    Mar 2012
    I'll explain the process and maybe you'll understand clearer.

    The first step is to type in a room name. This data is posted back to the page which PHP then deals with.. (?location=..., for example 109)

    Then a user will tick a radiobox and press Submit again. I didn't want the ID of the radiobox to appear in the URL because then people will start to mess around and could force the wrong data. Thus, I have POSTed this data to the same page (again).

    PHP checks that ?location is set, and that $_POST[radio] is also also. Now (corresponding) data will show.

    The problem I have is because I am not moving away from the original page, PHP posts the data and that loses which radiobox is checked. The radiobox goes from a checked state to an unchecked state because PHP has just essentially refreshed the page.

  4. #4
    Join Date
    Mar 2012
    Ok just a few things:

    First Next time please post some code here in the forum, don't use images! This 'cause it's easier to make a copy and paste of it and to explain you where's the problem.

    Second in the image you posted there is an error and I didn't see it.

    You wrote:

    echo "<form method='post'>
    You are forgetting the "action" attribute.

    You should write like this:

    echo "<form method='post' action='/path/to/your_page.php'>
    You have to do this also if you want to post it at the same page.
    The receiver page has to contain the code to analyze sent by post.

    You'll pick up the value with $_POST['name_of_radio']

    I post you an example of this concentrated in the same page:

    	if ($key==""){
    <form action="./test.php?key=1" method="post">
    <input type="radio" name="test" value="1"/>The value of radio is 1<br>
    <input type="radio" name="test" value="2"/>The value of radio is 2<br>
    <input type="radio" name="test" value="3"/>The value of radio is 3<br>
    <input type="submit" name="Select" value="Post your choice"/></form>
    		echo "Now I got the value of radio, it is $toprint";
    You can see its working here

    I hope that's enough to help you.

  5. #5
    Join Date
    Mar 2012
    Sorry we're actually talking about two different things. The post data works OK and I can see further information regarding the printer ID selected (with a checkbox), however what I would like to do is keep the checkbox checked value. I'll create a quick image to explain..

  6. #6
    Join Date
    Mar 2012
    Is that a little clearer?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.16545 seconds
  • Memory Usage 2,890KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (3)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates