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 12-15-2006, 10:13 AM   PM User | #1
Pompiuses
Regular Coder

 
Join Date: Jun 2002
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Pompiuses is an unknown quantity at this point
Submit content from a div tag

I have a div tag with text fields that I want to submit when user press the "Send" button (see code below). How can I do that?

Code:
<div id="anmelderBoks">
	Title: <input name="title" type="text" class="txtbred"/>
	<br /><br />
    	Title2: <input name="title2" type="text" class="txtbred"/>

	<input name="Send" type="button" class="btnBoks" onclick="MM_showHideLayers('anmelderBoks','','hide');MM_showHideLayers('anmeldelseSendt','','show')" value="Send"/>
</div>

Last edited by Pompiuses; 12-15-2006 at 10:17 AM..
Pompiuses is offline   Reply With Quote
Old 12-15-2006, 05:04 PM   PM User | #2
david_kw
Senior Coder

 
Join Date: Nov 2006
Posts: 1,000
Thanks: 0
Thanked 0 Times in 0 Posts
david_kw will become famous soon enough
The easiest way of course is to change the div to a form.

If for some reason you are unable to do that I think something like this would work too.

Code:
function sendDiv() {
  var div = document.getElementById("anmelderBoks");
  var titles = div.getElementsByTagName("input");
  var pairs = [];

  for (var i = 0; i < titles.length; i++) {
    pairs[i] = encodeURIComponent(titles[i].name) + "=" + encodeURIComponent(titles[i].value);
  }
  
  document.location = "action.php?" + pairs.join("&");  
}
.
.
.
<div id="anmelderBoks">
  Title: <input name="title" type="text" class="txtbred"/>
  <br /><br />
  Title2: <input name="title2" type="text" class="txtbred"/>

  <input name="Send" type="button" class="btnBoks" onclick="MM_showHideLayers('anmelderBoks','','hide');MM_showHideLayers('anmeldelseSendt','','show')" value="Send"/>
  <input name="Submit" type="button" onclick="sendDiv();" />
</div>
Of course as I was typing it became more complex than I thought so this probably has some minor bugs but I think the theory is sound. This would essentially work like a GET action.

david_kw
david_kw 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 09:58 AM.


Advertisement
Log in to turn off these ads.