Hello all,
I want to make like the toggle to add the content if it’s not there and delete it if it’s already there. I think it should be some function like this:
if ( content found ) {
delete it;
} else {
add it;
}, but i don’t know how to express “content found” in javascript… In PHP that would look like
if ( str_replace(re, “”, $string, $count) > 0) {
delete it;
} else {
add it;
}
What should i change in my script?
<script type="text/javascript">
function attachMe(elem) {
var txt = $("#post");
var re = new RegExp(elem, 'gi');
txt.val( txt.val().replace(re, ''));
txt.val( txt.val() + elem);
return false;
}
</script>
<form action="<?= $url; ?>" method="POST">
<label for="heading">Antraštė</label>
<br />
<input type="text" name="heading" id="heading" value="<?= htmlspecialchars($data['heading']); ?>" />
<br />
<label for="post">Turinys</label>
<br />
<textarea type="text" id="post" name="post"><?= htmlspecialchars($data['post']); ?></textarea>
<br />
<input type="submit" name="submit" value="Išsaugoti" />
</form>
<a href="#" onClick="return attachMe('<?= $row['url']; ?>');">Add/remove</a>
Thank you for any help!