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 6869517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:34:03+00:00 2026-05-27T03:34:03+00:00

First of, I’m new to ajax and Java Script.. I have spend days solving

  • 0

First of, I’m new to ajax and Java Script.. I have spend days solving this problem, but I still haven’t figured it out. I have read through threads with similar problems but I still can’t get it right. So here goes;

Quite simple I want post the checked value from from one of three radio buttons. All I get though is only the value of the first radio button..

I have tried several things, but I stripped down the code so it might be easier see where the problem is 🙂

The ajax

<script type"text="" javascript"="">
$(document).ready(function(){
    $("form#submit").submit(function() {
    // we want to store the values from the form input box, then send via ajax below
    var svar     = $('#svar').attr('value');
    var date     = $('#date').attr('value');
    var email     = $('#email').attr('value');

        $.ajax({
            type: "POST",
            url: "ajax.php",
            data: "svar="+ svar + "&email=" + email + "&date=" + date,
            success: function(){
                $('form#submit').hide();
                //$('form#submit :input').val("");
                $('div.success').fadeIn();
            }
        });
    return false;
    });
});
</script>

The form

<form id="submit" method="post" name="submit" action="">
            <fieldset>
            <legend>Dagens spørgsmål: <? echo $row['question'];?></legend>
                <br>
                <input type="radio" name="svar" id="svar" value="1"><? echo $row['opt1'];?>
                <br>
                <input type="radio" name="svar" id="svar" value="2"><? echo $row['opt2'];?>
                <br>
                <input type="radio" name="svar" id="svar" value="3"><? echo $row['opt3'];?>
                <br>
                    <input name="email" id="email" type="hidden" value="<? echo $email  ?>" />
                    <input name="date" id="date" type="hidden" value="<? echo $date  ?>" />

                <br><br>
                <button type="submit" class="button positive"> <img src="img/tick.png" alt=""> Svar på dagens spørgsmål </button>
            </fieldset>
        </form>

Ajax.php

<?php

    include ("dbc.php");

// CLIENT INFORMATION
    $email        = htmlspecialchars(trim($_POST['email']));
    $date        = htmlspecialchars(trim($_POST['date']));
    $svar        = htmlspecialchars(trim($_POST['svar']));



//stuff from answers

        mysql_query("INSERT INTO answers
        (`email`,`day`,`answer`)
        VALUES
        ('$email','$date','$svar')") or die(mysql_error());

?>

Hope one you of you smart guys have a solution.. because this thing i driving me crazy

  • 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-05-27T03:34:04+00:00Added an answer on May 27, 2026 at 3:34 am

    You have several problems.

    First, your HTML is invalid. An ID must be unique, so each radio button must have its own ID. You associate a group of radio buttons by giving them the same NAME. (Having a unique ID then lets you associate a LABEL with each one using the FOR attribute which increases accessibility by making it easier for screen readers and providing bigger click targets).

    Second, the value of a radio button is fixed. The question is “Is it successful or not?” and that is determined by seeing if it is checked or not. If you were doing this manually, you would have to loop over each radio button in the group until you found one that was checked (or use a selector that matched only the checked ratio button (:checked)).

    Third, you are building your form data by mashing together strings without making sure the data is URL safe (with encodeURIComponent).

    The solution is to forget about doing all this manually and just use the jQuery serialize method on the form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I know how to build a Java application. But I have
First of all Im new to vb 2010 and so far have enjoyed what
First let me preface this question by saying that I'm fairly new to Javascript.
First time user of stackoverflow, but I have followed its development over on Coding
First post, but I've been lurking around this site for a long while now,
First of all, I know I asked a similar question before but this one
First of all: I really tried to find a matching answer for this, but
First off, I am using Windows XP. I have multiple hard drives and it
First off, there's a bit of background to this issue available on my blog:
First let me say that I really feel directionless on this question. I am

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.