ntwiles
-
Posts
6 -
Joined
-
Last visited
Never
Posts posted by ntwiles
-
-
I'm working on a function that will insert tags into my textbox. I've modified a script I found online to get it to work almost perfectly. Here's the function:
function insertAtCursor(obj, text1, text2) { if(obj.selectionStart) { var start = obj.selectionStart; var end = obj.selectionEnd; if (start == end) { obj.value = obj.value.substr(0, start) + text1 + text2 + obj.value.substr(end, obj.value.length); } else { obj.focus(); obj.value = obj.value.substr(0, end) + text2 + obj.value.substr(end, obj.value.length); obj.value = obj.value.substr(0,start) + text1 + obj.value.substr(start, obj.value.length); } } }
Here's an example of the parameters:
<a href="#" onClick="insertAtCursor(document.postform.inputfield, '<div id=h1>','</div>')">Header</a>
The function works so that it either inserts "<div id=h1></div>" or those tags around a highlighted substring. The problem is, it won't insert at the 0th position. Meaning to get it to work, I have to insert one character or a space before I click the link to insert the tag. This happens with either of the two methods I described. Is this some sort of off by one error or a kind of bug?
-
Oh wow haha I really over thought that. Thanks for the help.
-
It seems like every new language I learn, I get this exact same issue. I want to make a clickable link that will go to "viewpost?postid=" and then add the value of a variable. The variable is an array. Here's what I'm trying. I'm not really sure why it doesn't work:
<?php $poststr = "<a href=\'viewpost.php?"+$postid[$num]+"\'>View This Post</a>"; echo $poststr; ?>
$postid[$num] in this example should be an integer. But what it outputs is really weird. It's not "View This Post" as a link, which is what I want. It just outputs the value of the variable $postid[$num] with no link. Can someone tell me what my problem is?
-
Thanks for the reply. I was afraid of that. Originally I tried to use javascript but that didn't work any better. If I create a cookie in php can I delete it using javascript without any problems?
Is there a way to go about deleting a cookie by clicking a link using php? Or would I just be better off going to the javascript section and asking about why my old script didn't work?
-
Hey guys I'm pretty new to both PHP and Javascript. I think my problem is a PHP one, not a Javascript one. But it involves both. I'm trying to delete a cookie by clicking a link.
I call the javascript function like so:
if (isset($_COOKIE["active"])) { echo "<a href='addpost.php'>Add Post</a> <a href onClick='eraseCookie()'>Log Out</a>"; }
And the function looks like this:
function eraseCookie() { <?php setcookie(active, 0, time()-3600); echo "It works"; ?> }
The function doesn't delete the cookie and doesn't echo "It works". Like I said this could be a Javascript error, not a PHP one, but I have to start somewhere. Can someone tell me what I'm doing wrong?
Insert Substring Function
in Javascript Help
Posted
Awesome, that was it. I love when a solution comes down to just one simple error. Thanks a lot for the help guys. This one has been bugging me for half a week.