views:

93

answers:

4

Dear All I am using jquery my html code

 <input type="radio" name="maritalstatus" id="maritalstatus" value="single"/>
  single
 <input type="radio" name="maritalstatus" id="maritalstatus" value="married"/>
  Married
 <input type="submit" id="clicksingleactive" />
 <input type="submit" id="clickmarriedactive"/>

if i submit the click "singleactive" button, the value of the single should checked, in case if i use the "clickmarriedactive" button the value of the married value should checked how to arrive this??

<select id="state" name="state">
 <option value="Ukrain"  >Ukrain</option>
 <option value="U.S"  >USA/option>  
</select>

If i click the "check ukrain button the value should select default in select list, as above.How to achieve in jquery any idea?

A: 

SELECT LIST

$("#state").val("Ukrain"); Sets the  Ukrain List
$("#state").val("U.S"); Sets the USA default
venkat
A: 

For 1st one i would prefer giving seperate id to 2 diff options married and single and use its id for selection as following:

<body>
    <input type="radio" name="maritalstatus" id="maritalstatus_1" value="single"/>
      single
     <input type="radio" name="maritalstatus" id="maritalstatus_2" value="married"/>
      Married
 <input type="submit" id="clicksingleactive" />
 <input type="submit" id="clickmarriedactive"/>
<br/>

</body>
<script>
    $(document).ready( function()
    {
        $("#clicksingleactive").click( function()
        {
            $("#maritalstatus_1").attr("checked","checked");
        });
        $("#clickmarriedactive").click( function()
        {
            $("#maritalstatus_2").attr("checked","checked");
        });
    });
</script>
KoolKabin
+1  A: 

First of all, you should change the IDs of your radio buttons. No two elements can have the same ID. (But keep the names same, that's what groups the two options together.)

 <input type="radio" name="maritalstatus" id="maritalstatus1" value="single"/>
  single
 <input type="radio" name="maritalstatus" id="maritalstatus2" value="married"/>
  Married

Then just add click handlers like these:

$('#clicksingleactive').click(function() {
  $('#maritalstatus1').attr('checked', true);
});
$('#clickmarriedactive').click(function() {
  $('#maritalstatus2').attr('checked', true);
});
casablanca
A: 

Something like that? (not sure I did fully understand your question)

<html>
<head>
    <title>S.O. 3287253</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"&gt;&lt;/script&gt;
    <script type="text/javascript">
    $(document).ready(function() {
        $('#clicksingleactive').click(function() {
            $('#maritalstatus-single').attr('checked', 'checked');
        });
        $('#clickmarriedactive').click(function() {
            $('#maritalstatus-married').attr('checked', 'checked');
        });
        $('#selectUkrain').click(function() {
            $('#state').val('Ukrain');
        });

    });

    </script>
</head>
<body>
<form id="maritalstatus">
    <input type="radio" name="maritalstatus" id="maritalstatus-single" value="single"/> single
    <input type="radio" name="maritalstatus" id="maritalstatus-married" value="married"/> Married
    <select id="state" name="state">
        <option value="" selected="selected">== choose ==</option>
        <option value="Ukrain">Ukrain</option>
        <option value="U.S">USA/option>  
    </select>
    <br/>
    <input type="button" id="clicksingleactive" value="Single"/>
    <input type="button" id="clickmarriedactive" value="Married"/>
    <input type="button" id="selectUkrain" value="Ukrain"/>
</form>
</body>
</html>
RC