user893246
user893246

Reputation:

PHP echo within form value

I'm attempting to echo a div tag within a HTML form value. Im unable to display the contents of the div tag without messing up the form value.

<?php echo '<div id="demo"></div>';?>


Form value...

<input type="text" id="term" value="<?php echo '<div id="demo"></div>';?>">


What's outputted... (What's echoed inside the form value should be the current longitude and latitude)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>Geolocation search</title>
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script id="data" type="text/javascript" src="js/search.js" xmlData="data/data.xml"></script>
</head>
<body onload="getLocation()">
<div id="controller">
  <label>Search Term:
    <input type="text" id="term" value="<?php echo '<div id="demo"></div>';?>">
  </label>
  <label>
    <select name="category" id="category">
      <option value="name">Name</option>
    </select>
  </label>
  <input name="Search" type="button" id="searchButton" value="Search">
</div>
<div id="result">&nbsp;</div>

<?php echo '<div id="demo"></div>';?>

<script>
var x=document.getElementById("demo");
function getLocation()
  {
  if (navigator.geolocation)
    {
    navigator.geolocation.getCurrentPosition(showPosition);
    }
  else{x.innerHTML="Geolocation is not supported by this browser.";}
  }
function showPosition(position)
  {
  x.innerHTML=" " + position.coords.latitude + 
  "<br> " + position.coords.longitude;  
  }
</script>
</body>
</html>

Is there soem other way to echo out the longitude and latitude from the that's loaded within the echo statement?

Upvotes: 1

Views: 3154

Answers (4)

user2807024
user2807024

Reputation:

Its because the HTTP headers, which you are sending like above, are telling the browser to expect a file to be downloaded. They are not telling browser to expect HTML content (default). Therefore the content you are sending in an echo is not getting displayed.

Both won't work together correctly although I'm sure you can find any work around but the point is that you only need those echo's while debugging so you can disable the mentioned header call while debugging and once everything is set, enable that again so file can download.

Upvotes: 0

Ajii Noguerra
Ajii Noguerra

Reputation: 69

     <label>Search Term:
        <input type="text" id="term" value="<?php echo '<div id="demo"></div>';?>">
     </label>

What i see from the above script is, you used a double quote to represent your attribute value.. and then single quote to handle the php echo value, then used a double quote again inside the div which makes the php code invalid because it stops its reading by the double quote you used. you might as well concatenate your php script or use an escape character for the string to be valid "\"

    <label>Search Term:
        <input type="text" id="term" value="<?php echo '<div id=\'demo\'></div>'; ?>" />
    </label>

    <?php echo "<div id='demo'></div>"; ?>

And may i just ask... What are you trying to echo out of the value? Is it really the div tag?

Upvotes: 0

OneOfOne
OneOfOne

Reputation: 99274

it's the "

change

<input type="text" id="term" value="<?php echo '<div id="demo"></div>';?>">

to

<input type="text" id="term" value="<?php echo "<div id='demo'></div>";?>">

Upvotes: 2

jordan
jordan

Reputation: 10752

You have double quotes around the word demo that are closing your value.

Try:

<?php echo "<div id='demo'></div>";?>

Upvotes: 0

Related Questions