开发者

Write text into input field with a PHP variable

I would like to write in an input field with a 开发者_StackOverflow中文版PHP variable. This is the current code I have:

JS:

<script type="text/javascript">
function reply(form, inp){
    form.texta.value = "@" + inp;
}
</script>

HTML:

 <a href="#" onClick="reply(form1, <?php echo $poster; ?>);">Reply ^</a>

 <form id="form1" name="form1" method="post" action="index.php"><input type="texta" name="texta" /></form>

This code however does not put the text of the variable in the input field. Sorry, I am a bit new to JavaScript.

Can anyone help me here?


Using my code I gave in the question and due to the answers/comments i have put single quotes around the php, and now it works perfectly. Thanks!


<input type="text" name="texta" value="<?php echo $poster; ?>" />


<a href="#" onClick="reply(form1, '<?php echo $poster; ?>');">Reply ^</a>

EDIT : You should Give Id to text box.


if you want it direct

<input type="texta" name="texta" value="<?=$poster?>" />

Or

use document.form.texta.value = value

or like this

document.forms["form"]["texta"].value = value

put any of these inside

function reply(form, inp){

}

<a href="#" onClick="reply(form1,"<?=$poster?>");">Reply ^</a>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜