Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8458825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:11:00+00:00 2026-06-10T13:11:00+00:00

I’m building a form with radio buttons. <form id=land name=input method=POST action=test.php> <input type=radio

  • 0

I’m building a form with radio buttons.

<form id="land" name="input" method="POST" action="test.php">
    <input type="radio" name="Albania" value="Albania" class="test">
    <input type="radio" name="Sweden" value="Sweden" class="test">
    <input type="radio" name="Norway" value="Norway" class="test">
    .....
    <input type="hidden" name="hidden" value="action">
    <input type="submit" value="Submit">
</form>

There are over 150 countries to choose from. And when you choose a country, the application I’m building shows a line chart representing the data for the country in question. I’ve built a script so that I can have multiple choices. Basically it builds an array of the selected values, and then builds a SQL query from the imploded array.

This works fine when I use the submit button to send the data. But I wanted the chart to update directly when the the user checked a radio button. I added

onClick='this.form.submit()'

to the input field and this works fine.

My problem is that I can’t choose two values now, eg, Norway and Sweden to compare the two, because once I check one radio button the page loads and the value disappears and the radio button is unchecked.

So. How do I send the query without the value disappearing?

Any help much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T13:11:01+00:00Added an answer on June 10, 2026 at 1:11 pm
    <input <?php if (!(strcmp($_POST['Albania'],"Albania"))) {echo 'checked="checked"';} ?> type="radio" name="Albania" value="Albania" class="test">
    <input <?php if (!(strcmp($_POST['Sweden'],"Sweden"))) {echo 'checked="checked"';} ?> type="radio" name="Sweden" value="Sweden" class="test">
    <input <?php if (!(strcmp($_POST['Norway'],"Norway"))) {echo 'checked="checked"';} ?> type="radio" name="Norway" value="Norway" class="test">
    

    But why don’t you use checkboxes instead; maybe the user what to uncheck one of the radio inputs.

    I recommend that you change the names of the radio buttons to: name="country[countryName]"
    it’s easier to retrieve the selected countries by doing implode()

    <input <?php if (in_array("Albania", $_POST['country'])) {echo 'checked="checked"';} ?> type="radio" name="country[Albania]" value="Albania">
    <input <?php if (in_array("Sweden", $_POST['country'])) {echo 'checked="checked"';} ?> type="radio" name="country[Sweden]" value="Sweden">
    <input <?php if (in_array("Norway", $_POST['country'])) {echo 'checked="checked"';} ?> type="radio" name="country[Norway]" value="Norway">
    

    Generate the radio buttons:

    <?php while($row = mysql_fetch_array($sth)) { ?> 
    <input class="className" type="radio" name="country[<?php echo $row['land']; ?>]" value="<?php echo $row['land'];?>" onClick='this.form.submit()' <?php if (in_array($row['land'], @$_POST['country'])) {echo 'checked="checked"';} ?> /><?php echo $row['land'];?> 
    <?php }?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.