Jump to content

Textarea Not Send


meddiecap

Recommended Posts

Hi,I'm using Javascript to POST data from a form. I noticed that Javascript ignores the textarea data.I know I have the naming correct, trying to process the data using php works fine. Also, the <input> fields work with JS.Right now, I use this to get the info from the texteare into a variable:var contact_motivatie = oForm.contact_motivatie.value;The corresponding formfield:<textarea name="contact_motivatie" type="text" value="" /></textarea>It only seems to work for input/hidden fields as far as i know.What's the method for textareas?

Link to comment
Share on other sites

But try this: take the value attribute out of your textarea tag. It does not belong there. The value of a textarea is the text that gets placed between the tags. It is possible that adding a value attribute set to "" is confusing your script. (A textarea also does not need a type attribute, though that is probably not causing your problem.)You may also be confusing your script by naming a variable with the same name as the textarea. I seem to remember IE having trouble with that. In general, try to give all page elements, variables, and functions unique names and IDs.If none of this works, post your page and script.

Link to comment
Share on other sites

Leaving the value attribute out did not solve the problem.Naming the variable the same as the texterea name should not cause any problems, i do the same with <input>-elements, it's for my own readability, and there it works.I'm not that good with JS but I was told to use names instead of ID's and type - where oForm is the name of the form -

var contact_motivatie = oForm.contact_motivatie.value;

instead of something like (not realy sure how it's written correctly :S)

var contact_motivatie = getElementbyID(..something.);

I remember this becaus I oftenly use dynamicly created formsPost: http://w3schools.invisionzone.com/index.php?showtopic=23921I'll post the code if it's still needed.

Link to comment
Share on other sites

Using names or IDs is fine with forms. In some situations, using names is more convenient. In others, it is less convenient. One way is not better than the other.From what you just posted, you have not fixed your problem yet. You have also not provided new information. Yes, your code is still needed. The HTML and the script.

Link to comment
Share on other sites

Your HTML is malformed (you have an extra forward slash in there):

<textarea name="contact_motivatie" type="text" value="" /></textarea>

That should read:

<textarea name="contact_motivatie"></textarea>

Link to comment
Share on other sites

Your HTML is malformed (you have an extra forward slash in there)
Good catch. If the browser interprets that opening tag to mean that the textarea element terminates, then it might not recognize the text content. But who knows? There is no standard way of interpreting malformed HTML.
Link to comment
Share on other sites

I change the malformaty in the HTML, removed the value parameter. It did not solve the problem, so here's the code:Btw, I use TinyMCE on the textareas, dunno if cause any problems.The Form:

<form action="" method="post" name="newdossier" class="dossier_formulier">	<input name="key" type="hidden" value="key" /> 	<table>	<tr>	<td>   	<label for="contact_motivatie">Contact motivatie:</label><br />	<textarea name="contact_motivatie" type="text"></textarea>	</td>	<td>	<label for="klacht">Klacht:</label><br />	<textarea name="klacht" type="text"></textarea>	</td>	<td>	<label for="ADL">ADL:</label><br />	<textarea name="ADL" type="text"></textarea>	</td>	</tr>	<tr>	<td>	<label for="pijnlokatie">Pijnlokatie:</label><br />	<textarea name="pijnlokatie" type="text"></textarea>	</td>	<td>	<label for="algemene_belastingen">Algemene Belastingen:</label><br />	<textarea name="algemene_belastingen" type="text"></textarea>	</td>	</tr>	</table>	<label></label><input type="button" id="button" onclick="add_dossier(this.form);" class="opslaan_knop" value=""/> 	<div id="bericht"></div></form>

THe JS

/* ---------------------------- *//* XMLHTTPRequest Enable *//* ---------------------------- */function createObject() {	var request_type;	var browser = navigator.appName;	if(browser == "Microsoft Internet Explorer")	{		request_type = new ActiveXObject("Microsoft.XMLHTTP");	}	else	{		request_type = new XMLHttpRequest();	}	return request_type;}var http = createObject();/* -------------------------- *//* INSERT *//* -------------------------- *//* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */var nocache = 0;function add_dossier(oForm) {			// Optional: Show a waiting message in the layer with ID insert_response	document.getElementById('bericht').innerHTML = "Even geduld..."	// Required: verify that all fileds is not empty. Use encodeURI() to solve some issues about character encoding.	var key = oForm.key.value;	var contact_motivatie = oForm.contact_motivatie.value;	var klacht = oForm.klacht.value;	var ADL = oForm.ADL.value;	var pijnlokatie = oForm.pijnlokatie.value;	var algemene_belastingen = oForm.algemene_belastingen.value;	// Set te random number to add to URL request	nocache = Math.random();	// Pass the login variables like URL variable		var locatie = 'assets/query/add_dossier.php';	var querystring = 'contact_motivatie='+contact_motivatie+'&klacht='+klacht+'&ADL='+ADL+'&pijnlokatie='+pijnlokatie+'&algemene_belastingen='+algemene_belastingen;			http.open('POST', locatie, true);	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")	http.onreadystatechange = insertSucces;	http.send(querystring);}function insertSucces() {	if(http.readyState == 4)	{		var response = http.responseText;		location.reload(true);	}}

Link to comment
Share on other sites

I've played with TinyMCE a few times, but it's been a while. What I remember is that it changes your DOM. Someone might know better than me, but it could be that your text doesn't really get entered into the textarea you think it does. Try using a DOM Inspector to find out exactly where your text is.

Link to comment
Share on other sites

I checked my DOM and it turns out, that my text is not directly in my textarea, but way way inside my TinyMCE in a <p> tag.DOM.jpgNow I know where to look for the text, how can I send it? What if I have more than one <p>-tagged text in that textarea?EDIT: Correcting the HTML concerning removing the value parameter and a '/' in the opening <textarea> worked for the textarea's without the TinyMCE

Link to comment
Share on other sites

It looks like you'll have to grab ALL the innerHTML of the iFrame's body element. I assume you chose TinyMCE because you want your users to be able to generate rich (formatted) text, so you'll need the <p> tags and all the other tags that TinyMCE puts in there. So the result is going to be a bunch of text and HTML tags, not just text.

Link to comment
Share on other sites

Huh, I've used tinymce and it just keeps a copy of the content as text inside the textarea element but sets the display of the textarea to none. What happens if you assign an ID to the textarea and then, at some point after adding content through tinymce, you do:

alert(document.getElementById("mytextareaID").value);

Link to comment
Share on other sites

@Deirdre's Dad: That's exactly why. I know how to get InnerHTML doing like: document.getElementById('insert_response').innerHTMLbut I can't do that, or better, don't want to. Can I do the innerHTML stuff not by Id, but by Name? (e.g. var straat = oForm.straat.InnerHTML;)..also, I just tried that, and it doesn't work...atleast, the example.I don't really want to change all the 'name'-parameters into 'id', because I use forms alot, and I use dynamicly create forms where I also use 'name' instead of 'id'.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...