Click the link, add text to textarea?
Let's say I have this javascript:
<script language="javascript" type="text/javascript">
function addtext() {
var newtext = document.myform.inputtext.value;
document.myform.description.value += newtext;
}
</script>
and I want to enable it, so I can click on the html link that says “add text” and I want the text to be @. $ username. (using PHP to insert username). Therefore, when you click the add text link, it will be placed in the @username text box. It's hard to imagine, and I'm not sure where to place the text and PHP exactly. Thanks!
Textarea:
<form Name ="myform" action="<?$posted = $_POST['description'];
$object->post_tweet($posted); ?>" method="post">
<table align="left" border="0" cellspacing="1" cellpadding="5">
<tr>
<td class="2">
<textarea name='description' class="color" COLS=84 ROWS=2 type="text" id="eBann" name="bannerURL" maxlength="100" size="60" onKeyUp="toCount('eBann','sBann','{CHAR} characters left',140);"></textarea>
<br>
<span id="sBann" class="minitext">140 characters left.</span>
</td>
</tr>
</table><BR><BR><BR>
<p><input type='submit' value='Tweet!' /><input type='hidden' value='1' name='submitted' /> </p>
</form>
This is what I want to do with the link:
<a href="#" onclick="addtext("@'. $twit->user->screen_name .'"); return false>reply</a>'
This gives me an error (I added the addtext function too).
EDIT: Got it! I had mistakes with 'and' ha ha wow, stupid mistake. Thanks everyone!
, . mish-mash HTML, JavaScript PHP, ?
<script language="javascript" type="text/javascript">
function addtext(text) {
document.myform.description.value += text;
}
</script>
...
<a href="#" onclick="addtext('@<?php echo htmlspecialchars(addslashes($userName)) ?>'); return false"
>reply</a>
: $userName is "TeaCast". HTML, <?php ?> , :
<a href="#" onclick="addtext('@TeaCast'); return false"
>reply</a>
!
:
href="#", , .addslashes()PHP .htmlspecialchars(), , ,'<''&', . , - ,"<script>alert('haha')</script>"(, HTML).
, , , javascript, :
<script language="javascript" type="text/javascript">
var username = '<?php echo htmlspecialchars(addslashes($userName)) ?>';
function addtusername() {
document.myform.description.value += "@" + username;
}
</script>
...
<a href="#" onclick="addusername(); return false">reply</a>
, Javascript , , php.