0

Hello everybody and good day ,

I am making a web application in php and mysql

Iam trying to make a page where a user can create a custom form eg. User can create custom forms so they can type the name of the input, however the place where they type the name of the input i have it formated like this:

<div contenteditable="true">
 <span spellcheck="false" id="a">Editable Content</span><em>o!</em>
</div>

so its not an input field .

How can i capture this information in a form , maybee with a hidden input field, a label or with jquery ?

if my question is not clear let me know i will edit ti it as soon as i get a chance .

VolkerK
  • 95,432
  • 20
  • 163
  • 226
Gunnit
  • 1,064
  • 5
  • 22
  • 45
  • Although this should be possible creating a new 'form' element inside the document, I don't understand why you should use spans instead of inputs... Is there a special reason for that? – Alessandro Desantis Oct 10 '11 at 13:27
  • Yes there is : its mainly for styling purpouses , this way it looks like normal text otherwise i would have to have an input field – Gunnit Oct 10 '11 at 13:36
  • What about styling with CSS? Just created: http://jsfiddle.net/ujLAV/ – ComFreek Oct 10 '11 at 13:41

2 Answers2

0

You can use javascript to collect the text inside the span.

This question is related How do I change the text of a span element in JavaScript

The answers mention document.getElementById("myspan").innerHTML which is the place that text resides. You'll want to change the "myspan" though.

Community
  • 1
  • 1
Tom Cerul
  • 1,773
  • 2
  • 13
  • 27
0

You have to use either a form or send the data with AJAX.

document.getElementById("your-form").onsubmit = function()
{
  var spanInput = document.createElement("input");
  spanInput.setAttribute("type", "hidden");
  spanInput.setAttribute("name", "spanData");
  spanInput.setAttribute("value", document.getElementById("a").innerHTML);

  this.appendChild(spanInput);

  return true;
}

// or
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){} // please change
xhr.open("POST", "your-script.php");
var spanData = document.getElementById("a").innerHTML;
xhr.send("spanData="+encodeURIComponent(spanData));
ComFreek
  • 29,044
  • 18
  • 104
  • 156