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