Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-24-2012, 10:35 AM   PM User | #1
basketmen
New Coder

 
Join Date: Mar 2007
Posts: 90
Thanks: 2
Thanked 0 Times in 0 Posts
basketmen is an unknown quantity at this point
I have TEXTAREA form, i want to add DROP DOWN LIST BOX beside it,like prefix in forum

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




Quote:
<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>
__________________
Whats up
basketmen is offline   Reply With Quote
Old 09-24-2012, 11:54 AM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,583
Thanks: 5
Thanked 864 Times in 841 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
That’s nothing JavaScript should do, it’s the job of the server side script that is processing the form data. You select something in the select element, hit the submit button, and the data will be stored in the database and can be retreived in any way you like.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 09-24-2012, 12:11 PM   PM User | #3
basketmen
New Coder

 
Join Date: Mar 2007
Posts: 90
Thanks: 2
Thanked 0 Times in 0 Posts
basketmen is an unknown quantity at this point
its should be able using javascript, i just want to joining the drop down value + the textarea value, then send them to database as 1 field
__________________
Whats up
basketmen is offline   Reply With Quote
Old 09-24-2012, 12:45 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Code:
var msgPrefix = document.comment_form.message_prefix.value; // the value is 1,2 or 3
value = "["+msgPrefix+"] "+ value;  // but I do not see any variable  named "value"

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
basketmen (09-24-2012)
Old 09-24-2012, 03:23 PM   PM User | #5
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 453 Times in 451 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
I'm assuming OP's looking for something like this...

Code:
var msgPrefix = document.comment_form.message_prefix.value; // the value is 1,2 or 3
document.comment_form.message.value = msgPrefix+" "+ document.comment_form.message.value;
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
basketmen (09-24-2012)
Old 09-24-2012, 04:56 PM   PM User | #6
basketmen
New Coder

 
Join Date: Mar 2007
Posts: 90
Thanks: 2
Thanked 0 Times in 0 Posts
basketmen is an unknown quantity at this point
many thanks and GBU xelawo, Philip M, and VIPStephan
xelawo code is working


btw in the bottom code, it is better i am using name, like currently
<select name="message_prefix">
<option value=""></option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>



or using id, like this
<select id="message_prefix">
<option value=""></option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>



because i tried using any both of them are working
__________________
Whats up
basketmen is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:17 PM.


Advertisement
Log in to turn off these ads.