Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [js] dynamiczne generowanie input, problem z radio
kufalo
post
Post #1





Grupa: Zarejestrowani
Postów: 251
Pomógł: 2
Dołączył: 24.08.2005

Ostrzeżenie: (0%)
-----


  1. <form id="f"></form>
  2. for(z=0;z<10;z++){
  3. i=document.createElement('input')
  4. i.type='radio'
  5. i.name='nazwa'
  6. document.getElementById('f').appendChild(i)
  7. }
  8. </script>
  9. </body>


Problem w tym ze wygenerowanych pol nie da sie zazwaczac (na pewno pod IE7)

Ten post edytował kufalo 14.05.2007, 12:36:32
Go to the top of the page
+Quote Post
revyag
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 2 258
Pomógł: 16
Dołączył: 21.09.2004
Skąd: Kielce

Ostrzeżenie: (0%)
-----


Źródło:
http://www.easy-reader.net/archives/2005/0...ns/#comment-444

Rozwiązanie:
  1. <form id="f"></form>

Kod
<script type="text/javascript">
function createElementWithName(){}
(function(){
    try {
        var el=document.createElement( '<div name="foo">' );
        if( 'DIV'!=el.tagName || 'foo'!=el.name ) {
            throw 'create element error';
        }
        createElementWithName = function( tag, name ) {
            return document.createElement( '<'+tag+' name="'+name+'"></'+tag+'>' );
        }
    } catch( e )    {
        createElementWithName = function( tag, name ){
            var el = document.createElement( tag );
            el.name = name;
            return el;
        }
    }
})();

for(z=0;z<10;z++){
    var element = createElementWithName("input","nazwa");
    element.setAttribute('type','radio');
    document.getElementById("f").appendChild(element);
}

</script>


--------------------
-------------

------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 05:05