Looking for something like:
$("input:radio:checked").previous("name", "original_name").attr("name","new_name");
I tried a few different seen around here but mostly get the error: Object Expected
Any help is appreciated.
Looking for something like:
$("input:radio:checked").previous("name", "original_name").attr("name","new_name");
I tried a few different seen around here but mostly get the error: Object Expected
Any help is appreciated.
As Ben S wrote in the comment to your original question, why do you need to change the name?
Let's say you have
<input type="radio" name="myRadio" id="radioChoice1" value="radioChoice1Value" />
<input type="radio" name="myRadio" id="radioChoice2" value="radioChoice2Value" />
If user selects 'radioChoice1' and clicks submit, browser will send
myRadio=radioChoice1Value to your CGI script. You can process this as you desire.
In case you insist on changing the name attribute, I am not sure what is the 'previous' method in your code.
Can you try,
$("input:radio:checked").attr("name","new_name");
And see if it works?
I can imagine that there could be cross browser problems if you try to change the name attribute. You can create a hidden input and store the name of the radio button selected by the user.
<input type="hidden" id="selectedRadioButton" />
$('#selectedRadioButton').val($("input:radio:checked").attr('name'));
EDIT:
Please post your HTML so that I can tell you what kind of values will be posted to CGI.
For example if you have
<input type="radio" name="transactionType" id="buy" value="buy" />
<input type="radio" name="transactionType" id="sell" value="sell" />
If user clicks on the first radio button 'buy', then in your CGI script value for 'transactionType' will be 'buy'.
I agree with the others that there is a better solution than to rename the input.
Having said that, and to answer your original question - I suggest that you assign ids to your radio inputs, and then use this code:
$("#inputId").attr("name","new_name");
I don't understand your use of .previous() - I can't find it in the jQuery documentation.