Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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 11:17 AM.

  • #2
    Senior Coder
    Join Date
    Nov 2006
    Posts
    1,000
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •