www.webdeveloper.com
Results 1 to 6 of 6

Thread: Check radio box (while loop problem)

  1. #1
    Join Date
    Mar 2012
    Posts
    22

    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.

    Code Capture.JPG

    Web Capture.JPG

    Thanks in advance!

  2. #2
    Join Date
    Mar 2012
    Posts
    22
    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
    Posts
    22
    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
    Posts
    22
    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:

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

    You should write like this:

    Code:
    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:

    Code:
    <?php
    	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>
    
    <?
    	}
    	else{
    		$toprint=$_POST['test'];
    		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
    Posts
    22
    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..
    Attached Images Attached Images
    • File Type: jpg 1.JPG (37.6 KB, 24 views)
    • File Type: jpg 2.JPG (21.3 KB, 20 views)
    • File Type: jpg 3.JPG (36.9 KB, 23 views)

  6. #6
    Join Date
    Mar 2012
    Posts
    22
    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



Recent Articles