views:

44

answers:

2

i have a script in jquery (that grabs a value from a select field and transfers it to an input field) that i need to do in mootools...i love jquery... mootools i dont know... not having much luck... here is the code:

<select size="1" class="inputbox select "
    id="producers" name="producers">
    <option selected="selected" value="">- Select an Article -</option>
    <option value="86">Acetaia Leonardi</option>
    <option value="50">Esperidia</option>
    <option value="49">Frescobaldi Laudemio</option>
    <option value="85">Primitivizia</option>
    <option value="87">Principato Lucedio</option>
    <option value="51">Rustichella d'Abruzzo</option>
</select>

<input type="text" value="" size="32" maxlength="50"
    name="producernamem" id="producernamem"
    class="inputbox text required required-enabled">
<!-- [example js] begin -->
<script type="text/javascript">
$(document).ready(function () {
    $('#producers').change(function () {
        pselected = $('#producers option:selected').text();
        $("input#producernamem[type='text']").val(pselected);
        alert (pselected);
    });
});
</script>
A: 

sorry i think i flubbed that by not wrapping the code...

<select size="1" class="inputbox select " id="producers" name="producers"><option selected="selected" value="">- Select an Article -</option><option value="86">Acetaia Leonardi</option><option value="50">Esperidia</option><option value="49">Frescobaldi Laudemio</option><option value="85">Primitivizia</option><option value="87">Principato Lucedio</option><option value="51">Rustichella d'Abruzzo</option></select>

<input type="text" value="" size="32" maxlength="50" name="producernamem" id="producernamem" class="inputbox text required required-enabled">
<!-- [example js] begin -->
<script type="text/javascript">
    <!--//<![CDATA[

    $(document).ready(function () {

  $('#producers').change(function () {
  pselected = $('#producers option:selected').text();
  $("input#producernamem[type='text']").val(pselected);

      alert (pselected);
  });
      });

    //]]>-->
</script>
liz
To reformat your code, don't do it in an answer, instead edit your question. Please delete this answer.
artlung
You can edit your original question instead of responding with an answer. It is easier for people to answer when they only have one version of the code to inspect.
Hawkcannon
+1 Hawkcannon. I went ahead and made the edits because I wanted to answer the question.
artlung
+3  A: 

The MooTools documentation is a good resource for this:

<script type="text/javascript">
window.addEvent('domready', function() {
    $('producers').addEvent('change', function(e){
        pselected = this.getSelected().get('text');
        $("producernamem").set('value', pselected);
        alert(pselected)
    });
});
</script>
artlung
this throws the following error: this.getSelected is not a function[Break on this error] (117 out of range 100)
liz
sorry this may be the fault of some underlying ajax functionality. the script looks like it should work but for some reason i think mootools is not being seen. will get back to you when i figure it out.
liz
http://www.jsfiddle.net/NBBR8/ it works with mootools 1.2+ (1.2.4 here).it may be an issue with .getSelected() if you're on mootools 1.1x (but then .get("text") and .set("value") will also throw errors).
Dimitar Christoff
ahhh... you are right. when i delete all that and just do a helloworld alert it works. are there equivalencies for the older version of mootools?
liz
i converted this to v1.1 and it works great! thanks..
liz
Glad I could help!
artlung