0

How to submit content of textarea when clicked on Share Div?

<div class="status">
    <textarea class="input" name="status" id="content" >
        So whats on your mind?
    </textarea>
</div>

<div class="button_outside" id="share">
    <div class="button_inside">Share</div>
</div>
4
Contributors
12
Replies
14
Views
5 Years
Discussion Span
Last Post by diafol
0

Just treat it as a button, use onclick event to do whatever you want

<div class="status">
    <textarea class="input" name="status" id="content" >
        So whats on your mind?
    </textarea>
</div>

<div class="button_outside" id="share" onclick="javascript:alert('hi')">
    <div class="button_inside">Share</div>
</div>
0

How to use jquery for this purpose?

Just treat it as a button, use onclick event to do whatever you want

<div class="status">
    <textarea class="input" name="status" id="content" >
        So whats on your mind?
    </textarea>
</div>

<div class="button_outside" id="share" onclick="javascript:alert('hi')">
    <div class="button_inside">Share</div>
</div>
0

Just think that its not div but its a button. If you find code for button, same way you write code for share id.

0

This is my function which results empty 'status'

<script type="text/javascript">
$(document).ready(function(){
 
	$('#share').click(function(){
		var DATA = 'status=' + status;
		alert (DATA);
		$.ajax({
		type: "POST",
		url: "insert.php",
		data: DATA,
		success: function() {
		  //display message back to user here
		}
	  });
	  return false;
	  
		
		
	});
	
});
</script>

Just think that its not div but its a button. If you find code for button, same way you write code for share id.

0

This is my final function .

<script type="text/javascript">
$(document).ready(function(){	
	$('#share').click(function(){		
		var status=$(".input").val();
 		var DATA = 'status=' + status;
		$.ajax({
		type: "POST",
		url: "insert.php",
		data: DATA,
		success: function() {
		  //display message back to user here
		}
	  });
	  return false;	
	});
});
</script>

How to add following

if(status == "So what's on your mind?")
  { //do nothing}
else
  {//insert values  
  }

there may be problem with insert.php, because alert is working fine when you click on share div.

0

Try this I hope it will work

<script type="text/javascript">
$(document).ready(function(){	
	$('#share').click(function(){		
            var status=$(".input").val();
	    if(status!="So what's on your mind?")	
            {
 		var DATA = 'status=' + status;
		$.ajax({
		type: "POST",
		url: "insert.php",
		data: DATA,
		success: function() {
		  //display message back to user here
		}
            }
	  });
	  return false;	
	});
});
</script>

Edited by urtrivedi: n/a

0

Thanks but not working. It does not insert anything to database.

Try this I hope it will work

<script type="text/javascript">
$(document).ready(function(){	
	$('#share').click(function(){		
            var status=$(".input").val();
	    if(status!="So what's on your mind?")	
            {
 		var DATA = 'status=' + status;
		$.ajax({
		type: "POST",
		url: "insert.php",
		data: DATA,
		success: function() {
		  //display message back to user here
		}
            }
	  });
	  return false;	
	});
});
</script>
0

Thats what I told you in my previous post, its not jquery fault, You need to review your insert.php page. Make sure it works fine independently.

0

trie

<div class="button_outside" id="share" onclick="javascript: document.forms["myform"].submit();">
    <div class="button_inside">Share</div>
</div>
0

Final Function is well without if else. When if else is added it works badly either it inserts "So what's on your mind?" or it stops working like your function.

Thats what I told you in my previous post, its not jquery fault, You need to review your insert.php page. Make sure it works fine independently.

0

Your textbox is showing:

So whats on your mind?

You're testing for

So what's on your mind?

Notice the apostrophe?

Anyway, I don't know if this is the best way to do it. You'd probably be better off if you detect a change to the textarea (dirty form) - rather than it being a certain value. This means you don't have to change the code if you decide to change the default value in the textarea.

have a look at this: http://stackoverflow.com/questions/2829881/detecting-html-textareas-change

Edited by diafol: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.