ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

switch form type.? jquery

December 12, 2008 11:51am

Subscribe [2]
  • #1 / Dec 12, 2008 11:51am

    Tom Schlick

    386 posts

    hey guys ive looked all over the jquery plugins site and could nto find something like this maybe one of you can point me in the right direction. im looking for a plugin that will change the type of a input when a select box changes it’s value…

    so id have a select with phone => text , name => text, and about => textarea. and when i would select each the type of the field next to it would change to that type. if anyone knows of anything like this please speak up!

    thanks in advance

  • #2 / Dec 12, 2008 12:37pm

    xwero

    4145 posts

    I’m not sure how you want to use this in real world situations but quick and dirty jquery code looks like this

    $('#inputchanger').changed(function(){
       var value = $(this).val();
       var text = [ "phone", "name" ];
       if(jQuery.inArray("John", text))
       {
           $(this).after('<input type="text" name="'+value+'">');
       }
       var textarea = [ "about" ];
       if(jQuery.inArray("John", textarea))
       {
           $(this).after('<textarea name="'+value+'"></textarea>');
       }
    });
  • #3 / Dec 12, 2008 12:41pm

    Tom Schlick

    386 posts

    sweet. thanks man. im using it for a page manager. users can change the type of field they are adding into the system dynamically. and each will be styled differently.

  • #4 / Dec 12, 2008 2:30pm

    Tom Schlick

    386 posts

    [removed][removed]
    [removed]
    $('#inputchanger').changed(function(){
       var value = $(this).val();
       var text = [ "phone", "name" ];
       if(jQuery.inArray("John", text))
       {
           $(this).after('<input type="text" name="'+value+'">');
       }
       var textarea = [ "about" ];
       if(jQuery.inArray("John", textarea))
       {
           $(this).after('<textarea name="'+value+'"></textarea>');
       }
    });
    [removed]
    <form name="test">
        <select name="changer" id="inputchanger">
            <option value="phone">Phone</option>
            <option value="about">About</option>
            <option value="Name">Name</option>
        </select>
    
    
    </form>

    what am i doing wrong?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases