Why I can not put value into input button?

I want to set a group of button, click them ,change the value and show into one div. Then clear the HTML tags and put the value into form input value. but it always fail.
I put the $s1 in the form input value directly. It show something wrong, I check it under firefox firebug, the form input value show <p> tag in it, so I use strip_tags($s1), it lost the value show empty. I copy the echo $s1 from firefox firebug source code and name it as $s2, then strip_tags($s2), it can work well. Then I make a session start on the top of the code and set $s1=$_SESSION[‘s1’],then put the $_SESSION[‘s1’] into the form input value, it also show nothing.
Where is wrong? and how to put a pure (no HTML tags)$s1 value into the form input value?
Thanks.


<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\\"><input id=\\"name\\" name=\\"name\\" value=\\"".$s2."\\" type=\\"hidden\\"><input type=\\"submit\\" value=\\"Submit\\" /></form> ";
echo $s3;
?>
<?
echo $_GET['post'];
?>

nevermind… Missed the PHP tags.

What is your meaning?
Put all the code in the
<?php
?>

Yes, it’s a good idea to always use <?php ?> instead of <? ?>. It’s more clear.

But regarding your question: how to put a pure (no HTML tags)$s1 value into the form input value? Is this what you need?


<?php
$s1 = 'Apple';
?>

<html>
<body>
  <form>
    <input type="text" name="fruit" value="<?php echo $s1 ?>" />
  </form>
</body>
</html>

So, I see you are trying to build a string with HTML code in it. I always use single-quotes and then I am not so confused. I know double quotes lets you evaluate variables within the string but I find concatenation easier. So here’s how I would put that input box in a string.


$s3 = '<input type="text" name="fruit" value="' . $s1 . '" />';

Hi boddy, I tried to use this method. It still not worked. 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…


<?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>

Hay, 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…


<?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>

In your code, you have:
$_SESSION[‘aa’] =‘<p id=“div1”></p>’;

and in your form, you have:
value=“<?php echo [I]strip_tags/I; ?>”

But when you strip the HTML and PHP tags from ‘<p id=“div1”></p>’ there is nothing left, so that’s why it displays empty.

I think I don’t understand your original problem: I want to set a group of button, click them, change the value and show into one div. Then clear the HTML tags and put the value into form input value.

In your form, you have three links: google, bbc, cnn. They are not buttons. Do you want them to be buttons? And when you click on one button or link, do you want the name (google, bbc, cnn) to go into the empty input box so you can press Submit? I’ll try to help if you explain a little more. :slight_smile:

Thanks Bobby. It is hard for me to explain clearly in english.
What I want is:
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 from 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.

If I read your post correctly you want to change a button value without refreshing the page when you click?
Then there is no use of using a php $_SESSION variable because it stores values across multiple pages.

So the solution is simple, use some Javascript

<html>
<head>
<title>Javascript example</title>
<script type="text/javascript">
function ChangeValue($button, $value)
{
document.getElementById($button).value=$value;
}
</script>
</head>
<body>
<input type="button" id="button1" onClick="ChangeValue('button2','Yeaaah! you clicked!!')" value="Click here to see my neighbor Button change -->">
<input type="button" id="button2" value="Value to begin with">
</body>
</html>

Sorta. It’s your highlighting mode that threw me off. The best two methods to highlight PHP are

[noparse]


and


Example of


[/noparse]


<tr>
  <td>
    <?= $hello ?>
  </td>
</tr>

[noparse]And

 [/noparse]

```php

&lt;tr&gt;
  &lt;td&gt;
    &lt;?= $hello ?&gt;
  &lt;/td&gt;
&lt;/tr&gt;

The highlight tag can also take “sql”, “javascript”, “css” or “html” as a parameter.


SELECT 
				p.`recordid` AS `recordid`, 
				p.`parentid` AS `parentid`, 
				p.`name` AS `name`, 
				p.`title` AS `title`,
				c.`class` AS class,
				c.`template` AS template,
								
				e.`type` AS event_type,
				e.`name` AS event_name,
				e.`recordid` AS event_recordid,
				ec.`class` AS event_class,
				ec.`template` AS event_template,
				
				o.`name` AS module_name,
				o.`recordid` AS module_recordid,
				o.`title` AS module_title,
				oc.`class` AS module_class,
				oc.`template` AS module_template,
				
				oe.`type` AS module_event_type,
				oe.`name` AS module_event_name,
				oe.`recordid` AS module_event_recordid,
				oec.`class` AS module_event_class,
				oec.`template` AS module_event_template

			FROM ".GZ."pages p
			LEFT JOIN ".GZ."map pm ON pm.pageid = p.recordid
			LEFT JOIN ".GZ."events e ON e.recordid = pm.eventid
			LEFT JOIN ".GZ."modules o ON o.recordid = pm.moduleid
			LEFT JOIN ".GZ."map ec ON ec.eventid = e.recordid AND ec.moduleid = 0
			LEFT JOIN ".GZ."map oc ON oc.moduleid = o.recordid AND oc.eventid = 0
			LEFT JOIN ".GZ."map c ON c.pageid = p.recordid AND c.eventid = 0 AND c.moduleid = 0
			LEFT JOIN ".GZ."map om ON om.moduleid = o.recordid
			LEFT JOIN ".GZ."events oe ON oe.recordid = om.eventid
			LEFT JOIN ".GZ."map oec ON oec.eventid = oe.recordid";


// script.aculo.us scriptaculous.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008

// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
// 
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// For details, see the script.aculo.us web site: http://script.aculo.us/

var Scriptaculous = {
  Version: '1.8.1',
  require: function(libraryName) {
    // inserting via DOM fails in Safari 2.0, so brute force approach
    document.write('&lt;script type="text/javascript" src="'+libraryName+'"&gt;&lt;\\/script&gt;');
  },
  REQUIRED_PROTOTYPE: '1.6.0',
  load: function() {
    function convertVersionString(versionString){
      var r = versionString.split('.');
      return parseInt(r[0])*100000 + parseInt(r[1])*1000 + parseInt(r[2]);
    }
 
    if((typeof Prototype=='undefined') || 
       (typeof Element == 'undefined') || 
       (typeof Element.Methods=='undefined') ||
       (convertVersionString(Prototype.Version) &lt; 
        convertVersionString(Scriptaculous.REQUIRED_PROTOTYPE)))
       throw("script.aculo.us requires the Prototype JavaScript framework &gt;= " +
        Scriptaculous.REQUIRED_PROTOTYPE);
    
    $A(document.getElementsByTagName("script")).findAll( function(s) {
      return (s.src && s.src.match(/scriptaculous\\.js(\\?.*)?$/))
    }).each( function(s) {
      var path = s.src.replace(/scriptaculous\\.js(\\?.*)?$/,'');
      var includes = s.src.match(/\\?.*load=([a-z,]*)/);
      (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider,sound').split(',').each(
       function(include) { Scriptaculous.require(path+include+'.js') });
    });
  }
}

Scriptaculous.load();


body {
	min-width: 1024px;	
}

#legend li,.legend li
{
	display:inline;
	list-style-type:none;
	padding-right:20px;
}

/**
 * This CSS file is for persistent CSS structures. Anything that might be
 * customized per county should be reposited in that template's default.css
 * or print.css files.
 * $Id: common.css 12687 2010-09-28 14:32:15Z  $
 */
#legend,.legend
{
	background-color:#FFFFE8;
	border:1px solid #ccc;
	margin-top:10px;
}
#ProductionWarning {
	background: #900;
	color: #fff;
	text-align: center;
	padding: 3px;
	border-bottom: 1px solid #000;
	font-weight: bold;
	font-size: 12px;
}

#loading_box
{
	-moz-opacity:1px;
	background-color:#FFF;
	border:2px solid #000;
	filter:alpha(opacity=100);
	left:25%;
	margin-left:auto;
	margin-right:auto;
	max-height:50%;
	min-height:33%;
	opacity:1px;
	overflow:auto;
	padding:10px;
	position:absolute;
	text-align:left;
	top:33%;
	width:50%;
	z-index:10000;
}


&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;&lt;/title&gt;
		
				
								&lt;script type="text/javascript" src="/js/lib/prototype.js"&gt;&lt;/script&gt;
						&lt;script type="text/javascript" src="/js/src/effects.js"&gt;&lt;/script&gt;
						&lt;script type="text/javascript" src="/js/src/dragdrop.js"&gt;&lt;/script&gt;
						&lt;script type="text/javascript" src="/js/Gazelle.js"&gt;&lt;/script&gt;

							
				
			&lt;/head&gt;
	&lt;body&gt;
		&lt;div&gt;
	&lt;h1&gt;ok&lt;/h1&gt;
	
	&lt;h2&gt;Hello, I'm a module!&lt;/h2&gt;&lt;/div&gt;	&lt;/body&gt;
&lt;/html&gt;

Thanks, Pixel Boy, I think you got it. It cannot be done in php without refreshing the page.

Thanks to all, you are friendly.

Hi Bobby. and me, I think it is hard to complete the job with php.

PixelBoy, it is a amusing script. For my stupid, why getElementById use

$button

not a button number? And use

$value

?

hello, Michael Morris, sorry for that I just know [ code ] before.

I hope we are friendly! :slight_smile:

Are you sure the page cannot refresh? If it can refresh, then php can do it.

You asked why use $button and not a number? It’s a function, so it is similar to PHP. Here…


<input type="button" id="button1" onClick="ChangeValue('button2','Yeaaah!')"
<input type="button" id="button2" value="Value to begin with">

See, the first button has onClick, so when you click it, it will execute the function
ChangeValue(‘button2’,‘Yeaaah!’). What does that function do? Here it is.


function ChangeValue([COLOR="Red"]$button[/COLOR], [COLOR="Blue"]$value[/COLOR]) {
  document.getElementById([COLOR="red"]$button[/COLOR]).value=[COLOR="blue"]$value[/COLOR];
}

So ‘button2’ goes into $button and ‘Yeaaah!’ goes into $value.
That’s how you pass values to a function. This is almost the same in any language, so it’s important to know. :tup:

Thanks, Bobby Hall.
This is almost the same in any language, so it’s important to know.
Yes, I shall learn morn, there are many many thing I do not know. So I always post question for help.
Now, here are many friends like you, help me enthusiastic, I am so happy.
٩(•̮̮̃•̃)۶