Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2006
    Messaggi
    292

    Aggiungere un elemento dentro una lista e inserirlo nel database

    Ciao ragazzi,
    Dovrei aggiungere un elemento dentro una lista e poi inserirlo nel database, nella lista ci sono riuscito ma siccome sono un po a digiuno di javascript / ajax come faccio a richiamare la pagina per l'inserimento e postare il campo con Jquery?
    Qui sotto il mio codice:




    Javascript:
    codice:
    <script language="javascript">
    function addElement(){
    // Get the value into the input text field
    var element=document.getElementById('newElement').value;
    if(element==""){
    // Show an error message if the field is blank;
    document.getElementById('msg').style.display="block";
    document.getElementById('msg').innerHTML = "Error! Insert a description for the element";
    }else{
    // This is the <ul id="myList"> element that will contains the new elements
    var container = document.getElementById('myList');
    // Create a new[*] element for to insert inside <ul id="myList">
    var new_element = document.createElement('li');
    new_element.innerHTML = element;
    container.insertBefore(new_element, container.firstChild);
    // Show a message if the element has been added;
    document.getElementById('msg').style.display="block";
    document.getElementById('msg').innerHTML = "Elemend added!";
    // Clean input field
    document..getElementById('newElement').value="";
    }
    }
    </script>
    Html:
    codice:
    <style>
    body{font-family:'Lucida Grande', Verdana, sans-serif; font-size:14px; color:#666666;}
    a:link, a:visited{color:#0033CC;}
    h3{border-bottom: solid 2px #DEDEDE; padding:6px 0; color:#000000;}
    #msg{background:#FFFFCC; margin:10px; padding:4px; display:none;}
    </style>
    
    <h3>Add a new element into a <ul> list</h3>
    Add a new element into the list (press "submit" button)
    
    
    <input name="newElement" id="newElement" type="text" value=""/>
    <input type="button" value="submit" name="submit" onClick = "javascript:addElement()"/>
    
    <div id="msg"></div>
    
    <ul id="myList">[/list]

    Grazie

    M4tt86

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2006
    Messaggi
    292
    up

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2006
    Messaggi
    292
    up

  4. #4
    Utente di HTML.it
    Registrato dal
    Feb 2006
    Messaggi
    292
    Anche se trovate un altro script jquery già pronto va bene lo stesso, ma vi prego di aiutarmi.

  5. #5
    Utente di HTML.it
    Registrato dal
    Feb 2006
    Messaggi
    292
    up

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.