4 Replies - 1493 Views - Last Post: 24 September 2012 - 06:01 AM

#1 basketmen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 07-May 12

I have TEXTAREA form, i want to add DROP DOWN LIST BOX beside it

Posted 24 September 2012 - 02:45 AM

Hi guys

i have comment form code (in black colour) below, user type the comment in TEXTAREA, and click the Submit button

i want to add DROP DOWN LIST BOX before it, that user can choose, and add that DROP DOWN value with the text in TEXTAREA into database, so just like prefix in forum

i already tried below code (in red), but still not working, please help guys what is the right code




<div>
	<script language="javascript" type="text/javascript">	     

$(document).ready(function(){

	$("#form_submit").click(function() { 
	document.getElementById("form_submit").disabled = true;	
	checkcomment = trim(document.comment_form.message.value);

	if (checkcomment.length > 0) {
	var msgPrefix = document.forms["comment_form"].elements["message_prefix"].options[document.forms["comment_form"].elements["message_prefix"].selectedIndex].value;	     
	       value = "["+msgPrefix+"] "+value;
	comment_submit();
	}
	else {
	alert("Please type some text");
	}
	document.getElementById("form_submit").disabled = false;	
	});
	
	function comment_done() {  }
	function comment_submit()
	{
		$.ajax({
			type: "POST",
			url: "/targetfile.php",
			data: $("#comment_form").serialize(),
			success: function(data){
				if (data == "SUCCESS") {
					//alert("Successful");
					document.comment_form.message.value = "";
					setTimeout (CommentAjax,0);
					}
				else {
					alert("Error: "+data);
					}
			}
		});
	}
	
});
</script> 			

<form id="comment_form" name="comment_form" method="post">
                    <input type="hidden" name="heu" value="addreply" />
                    <input type="hidden" name="muser" value="' . $this->muser . '" />
                    <input type="hidden" name="modid" value="' . $this->douid . '" />
                    <input type="hidden" name="tun" value="0" />


                    <select name="message_prefix">                
                        <option value=""></option>
			<option value="1">One</option>
                        <option value="2">Two</option>
                        <option value="3">Three</option>                
                    </select>
		
					<textarea name="message" rows="4" cols="20" style="width: 70%;"></textarea><br />

                    <input type="button" id="form_submit" value="Submit" />
                </form></div>

This post has been edited by JackOfAllTrades: 24 September 2012 - 03:38 AM
Reason for edit:: Changed quote tags to code tags, removed color tags


Is This A Good Question/Topic? 0
  • +

Replies To: I have TEXTAREA form, i want to add DROP DOWN LIST BOX beside it

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: I have TEXTAREA form, i want to add DROP DOWN LIST BOX beside it

Posted 24 September 2012 - 03:39 AM

Post your code in CODE tags, not QUOTE tags!

Quote

still not working


Does it blow up your computer? Kill your dog? What does "still not working" mean?
Was This Post Helpful? 1
  • +
  • -

#3 basketmen  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 07-May 12

Re: I have TEXTAREA form, i want to add DROP DOWN LIST BOX beside it

Posted 24 September 2012 - 04:02 AM

View PostJackOfAllTrades, on 24 September 2012 - 03:39 AM, said:

Post your code in CODE tags, not QUOTE tags!

pardon me, but the colour is not showing when using code tag


Quote

still not working


Does it blow up your computer? Kill your dog? What does "still not working" mean?


i mean the comment in the form is not submited using above code
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3717
  • View blog
  • Posts: 5,979
  • Joined: 08-June 10

Re: I have TEXTAREA form, i want to add DROP DOWN LIST BOX beside it

Posted 24 September 2012 - 05:14 AM

Your code is very inconsistent.

First, on line #6, you use jQuery to get the form_submit element: $("#form_submit"). But on lines #7 and #18, you use the normal Javascript DOM to get that same element: document.getElementById("form_submit"). - Also note that, since lines #7 and #18 are inside an event callback on the #form_submit element, the this keyword references that element.

Second, on lines #8 and #31 and you use document.comment_form.message to reference a form element, but on line #11 you do: document.forms["comment_form"].elements["message_prefix"].

And your indentation is all over the place, which is an especially bad thing in the Javascript world.


I suggest that you pick one of these methods. Since you've already got jQuery loaded, you may as well make use of that. It's syntax is generally easier to use than the others.


As for the actual problem. Line #12 strikes me as odd. What is the value variable, and why are you assigning it a value?
Was This Post Helpful? 1
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: I have TEXTAREA form, i want to add DROP DOWN LIST BOX beside it

Posted 24 September 2012 - 06:01 AM

Just reeks of random copy/paste, eh?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1