开发者

How to capture a value not through an input field in a form using php and mysql ?

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 .


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.


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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜