Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

youlichika

macrumors member
Original poster
Aug 27, 2010
35
0
Code:
<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>
<p id="div1"></p>
<?
$s1 ="<p id=\"div1\"></p>";
$s2 =str_replace(array('<p id="div1">','</p>'), array('', ''), $s1);
echo $s1;
echo $s2;
$s3="<form name=\"input\" action=\"8.php\" method=\"get\"><form name=\"input\" action=\"8.php\" method=\"get\"><input id=\"name\" name=\"name\" value=\"".$s2."\" type=\"hidden\"><input type=\"submit\" value=\"Submit\" /></form> ";
echo $s3;
?>
<?
echo $_POST['post'];
?>

Hello, Why I can not put value into input button? Where is wrong? Thanx.
 
Where to begin?
  1. First you're setting $s1 equal to "<p id=\"div1\"></p>"
  2. Next you use str_replace to find and replace "<p id=\"div1\"></p>" in $s1 with "" and make that the value of $s2. You just made the value of $s2 = "", so the value of your hidden input is going to be blank.
  3. You've duplicated your opening <form> tag (Perhaps a copy/paste error)
  4. You're trying to echo $_POST data and you have the action for your form set to "get"
  5. You're trying to echo the 'post' value of your form, and there is no field with the name 'post'
Perhaps if you could give us a better idea of what you're trying to do with this code we could be more helpful. Personally this snippet by itself doesn't seem to do much of anything
 
Thanks, it is my post error. The whole code is too long.
I just want to ask 1 and 2. :confused:How to get a pure value from $s1(remove all the html tag) and put it into <form> input value?
I tried put the $s1 directly, it did not worked. I check it under the firefox firebug, it showed <input id="name" name="name" value="<p id="div1">http://www.bbc.co.uk</p>" type="hidden">
 
Hi, I have found something wrong. The value in <p id="div1"></p> can not be stored. Even I add a session.I checked it in the Firefox Firebug, it display empty.
How to remember the value in <p id="div1"></p>? Is it just a virtual value?
Strangely... use echo $_SESSION['aa'] can clearly see the value...

Code:
<?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>
 
You're not getting a value in the input tag because you're taking it out.
The value of $_SESSION['aa'] is set to '<p id="div1"></p>'
The value of strip_tags($_SESSION['aa']) is therefore empty. That's what strip_tags() does, it removes html tags from a variable.

Put some text in your paragraph when you set the variable and you'll see the text appear as a value in your hidden field.
PHP:
<?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">This is a paragraph</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>
 
Hello Darth, you are right. I paid my all attention in the php code, and ignore the js code.

just add
document.getElementById('yourRenamedHiddenInput').value = title;
in js code

and put id="yourRenamedHiddenInput" in input field, it works.

Now I solved my question. Thank u very much.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.