Hi all,
I hope you can help. I have a bug when adding a value to my sortable
list - it all works fine when data is present in the 2 text boxes, my
issue is when there is no data.
When the 2 text boxes are empty and I press the button to submit
nothing happens UNTIL I enter any value into the boxes, as soon as
both boxes have a character then it adds it to the list automatically.
Obviously I want to not add blank data but also if the user presses
add without data then the add "reset" so the user has to press it
again before any data can be added.
---------------------------------------------------------------------------------------------------------------------------------------------
Here is the relevant code I believe:
HTML Index Page - Form:
<form action="javascript:insertChunk()" method="post">
<h2>Create New Chunk</h2>
<h3>Chunk Name</h3>
<input type="text" id="txtChunkTitle" name="txtChunkTitle" length="42"/
>
<br />
<h3>Chunk Description</h3>
<textarea name="txtChunkContent" id="txtChunkContent" cols="30"
rows="15"></textarea>
<br />
<div id="addChunk">
<input type="button" name="submit" value="CLICK TO CREATE CHUNK"
onclick="insertChunk()" />
</div>
</form>
JavaScript:
function insertChunk()
{
if (xmlHttp)
{
params = "";
var chunkTitle= trim(encodeURIComponent(document.getElementById
('txtChunkTitle').value));
var chunkContent = trim(encodeURIComponent(document.getElementById
('txtChunkContent').value));
if (chunkTitle && chunkContent) // makes sure Chunk isnt null
{
params = "?chunkTitle=" + chunkTitle + "&chunkContent=" +
chunkContent;
}
if (params) cache.push(params);
try
{
// only continue if the connection is clear and cache is not
empty
if ((xmlHttp.readyState == 4 || xmlHttp.readyState == 0) &&
cache.length>0)
{
// get next set of values from cache
var cacheEntry = cache.shift();
xmlHttp.open("GET", "addChunkList.php" + cacheEntry, true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-
form-urlencoded");
xmlHttp.onreadystatechange = executeChunkStateChange;
xmlHttp.send(null);
}
else
{
setTimeout("insertChunk();", 1000);
}
}
catch (e)
{
displayError(e.toString());
}
}
}
function executeChunkStateChange()
{
if (xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200)
{
// if OK then proceed to chunkUpdate
chunkUpdate();
}
else
{
displayError(xmlHttp.statusText);
}
}
}
function chunkUpdate()
{
var response = xmlHttp.responseText;
document.getElementById("chunksList").innerHTML = response;
Sortable.create("chunksList");
document.getElementById("txtChunkTitle").value = "";
document.getElementById("txtChunkContent").value = "";
}
--------------------------------------------------------------------------------------------------------------------------------------------
Hope someone can help with this :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---