Well,

First of all, i would put a hidden text field to do the reversing,
since i think if the user sees the field field order being reversed,
he will change it back the way it was.
This way, you get to read the field with the propper order.
So the html would look like:
<input type="text" name="username" id="username">
<input type="hidden" name="proppername" id="proppername">
<div id="radiobttns">
</div>

Then you add some code
username = $('username').value

//get the username
if (username!=''){
 //is there is something in there, then
 var unamearr = username.split(' ')
 if (unamearr.length==2){
  //if there are more than 3 spaces in there
  //kill the previous radio buttons
  $('radiobttns').setHTML('');
  //loop the array and add the radio buttons
  unamearr.each(function(uname, ind){
   var rb = new Element('input',
{'type':'radio'}).setHTML(uname.substr(1,1)).injectInside($
('radiobttns'))
   //add a click event to each radio button
   rb.addEvent('click',{function(
     //add the username the user just selected first
     proppername.value = uname + ' ';
    // then add the rest of the names
     if (unamearr[0]!= uname){proppername.value += unamearr[0];}
     if (unamearr[1]!= uname){proppername.value += unamearr[1];}
     if (unamearr[2]!= uname){proppername.value += unamearr[2];}
   )})
 })
}
}

Off the top of my head...
This can probably be done better, but with 3 seconds to spare, this is
the best i can come up with.
You might want to check the syntax, and not sure if substr should be
used....


On Oct 20, 11:12 am, mckurban <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I'm working on the form which uses javascript field to generate radio
> buttons, I need to to allow people to sort their entries as per
> selected button:
>
> Example
>
> Text field:   James Martin Brown
>
> We should have 3 buttons generated:
> * James
> * Martin
> * Brown
>
> Actually we should have:
> * J
> * M
> * B
>
> In the database I can store only 1 character to sort users.
>
> Now if we select Brown (or B) button, our text field should change to
> Brown James Martin (selected button should display first in the text
> field) and then the rest of the text as was
>
> At this point I've managed to get to the point where I have text field
> which generates radio buttons and displays only 1st character (in the
> database I can save only 1st character) what I need now is to be able
> to use the sort button to change the order of the actual text in the
> input text field - hope this makes sense ;)
>
> My code:
>
>  <td class="formlabel" align="left" valign="top">
>
>   <script type="text/javascript">
>
>   function update_radio_buttons() {
>     var userName =
> document.forms.contentForm.elements.data_name.value;
>     var userName = userName.split(' ');
>     var myRadioHTML = '';
>     var startValue = '<%$value%>';
>     for (var i =0; i < companyName.length; i++) {
>       if (userName[i] != '') {
>         var newRadioButton = '<p><input type="radio" name="<%$name%>"
> value="' + userName[i].charAt(0) +'" />' + userName[i].charAt(0) + '</
> p>';
>
>         myRadioHTML = myRadioHTML + newRadioButton;
>       }
>     }
>     document.getElementById("my_radio_buttons").innerHTML =
> myRadioHTML;
>   }
>   </script>
>
> then in the form I just use this code to call above function
>
> <div id="my_radio_buttons"></div>
>    <script type="text/javascript">
>     update_radio_buttons();
>    </script>
>
> It would be great to see an example of such a code
>
> many thanks
>
> mck

Reply via email to