Have an account? Sign in
Login  Register  Facebook
Why I can not put value into input button?
Hi, I have a long height page. There are a group of links in one div at the top of the page. Like google, bbc, cnn. When I click each of the link, it can post the different value to a button in another div at the bottom of the page. click the bottom can post the value witch is like google, bbc, cnn.
So I try to post $_SESSION['aa'] into the value of the button so that one button can post the different value. And I want the link of google, bbc, cnn and the bottom left a long distance, click all of the link will without refresh the page.
Thanks

<?php
session_start();
?>
<script language="javascript">
function thelink(title)
{
    document.getElementById('div1').innerHTML = title;
}
</script>
<li><a href="#" title="http://www.google.com" onclick="thelink('http://www.google.com')">google</a></li>
<li><a href="#" title="http://www.bbc.co.uk" onclick="thelink('http://www.bbc.co.uk')">bbc</a></li>
<li><a href="#" title="http://www.cnn.com" onclick="thelink('http://www.cnn.com')">cnn</a></li>
<?php
$_SESSION['aa'] ='<p id="div1"></p>';
echo $_SESSION['aa'];
?>
<form name="input" action="8.php" method="get"><input id="name" name="name" value="<?php echo strip_tags($_SESSION['aa']); ?>" type="hidden"><input type="submit" value="Submit" /></form>
Started: September 21, 2011 Latest Activity: September 21, 2011 postvalue
1 Answer
Use the same javascript, with the value property:
function thelink(title) {
  document.getElementById('div1').innerHTML = title;
  document.getElementById('yourRenamedHiddenInput').value = title;
}
And change the id and name of your input to something more unique:
<input id="yourRenamedHiddenInput" name="titleStorage" 
  value="<?php echo strip_tags($_SESSION['aa']); ?>" type="hidden">

Posted: MacOS
In: September 21, 2011

Thanx, It works. Now I know I should not pay my attention in the php code, I should change my js code. :_)
September 21, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer