...

View Full Version : Submit content from a div tag



Pompiuses
12-15-2006, 11:13 AM
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?



<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>

david_kw
12-15-2006, 06:04 PM
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.



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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum