views:

47

answers:

3

How can I reload or set to default (using javascript or jquery) only a particular tag (or id) in my html page. For instance, if I want to set the following select option to default "selected", if something else is currently in selection, without reloading the entire page through javascript confirm() function as follows:

var answer = confirm("Clicking 'OK' will revert to the default option.");
if (answer) { // ie, if i click 'OK'
    selected = $(this).val();
    //set the select drop-down option to "aaa" 
    //location.reload() reloads the entire page
} else {
    $(this).val(selected);
}

...more...
<select size="1" name="choice" id="choice">
    <option value="aaa" selected>aaa</option>
    <option value="bbb">bbb</option>
    <option value="ccc">ccc</option>
</select>
...html...

Many thanks in advance.

A: 

you can use UpdatePanel control and call Update method.

<asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="updateList">
    <ContentTemplate>
        <select size="1" name="choice" id="choice">
            <option value="aaa" selected>aaa</option>
            <option value="bbb">bbb</option>
            <option value="ccc">ccc</option>
        </select>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="refreshButton" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
<asp:Button runat="server" ID="refreshButton" Text="Refresh" />
DEVMBM
That's only limited to ASP.NET. And the question doesn't have anything to do with AJAX.
xar
that's ok , thank you for your notice
DEVMBM
A: 

The DOM property defaultSelected mirrors the original HTML-set selectedness of an option:

$('#choice option').each(function() {
    this.selected= this.defaultSelected;
});

Similarly, defaultValue in textual inputs, and defaultChecked in checkbox/radio.

bobince
A: 

the best way is use jquery.ajax and fill the location(target DOM element) with the data received from server.

jQuery.ajax({
     url:'call_this_url',
     type:'POST/Get',
     data:{selectedValue:selected},
     dataType:TEXT,  //in your case iam expecting url would return html, in other cases you may set it to json,jsonp, etc
     function(dataReceivedFromServer){
         jQuery('#target').html(dataReceivedFromServer)
     }
});
Praveen Prasad