Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2009
    Thanked 0 Times in 0 Posts

    button onclick for different div. updater with prototype.

    hi everyone.
    i'm driving myself mad with this... i dont know what i'm doing wrong. any help, thanks in advance! sorry to ask, but i couldnt find a way to do this in google. there are a lot of options out there, but seem too strange to me (requests, events observers, etc).

    i want a page with 2 divs (div1, to hold the buttons, and div2, to get the results). In one of them, i put a select and two buttons, in the other, i just want the results: if the select changed, or which button was pressed.
    i'm using prototype, but it seems not to work. i think it's the most suitable (and easy!!) to do what i want. kind of new with this...

    ps: note the buttons are not submit.

    i've done a function which sends the data of the form and sends it to a specific div to execute a specific php.

    the code:

    main html file:

    <script src="utils/Scripts/prototype.js" type="text/javascript"></script>
    <script type="text/javascript">

    function sendf(formul, divi, php)
    var params = Form.serialize($(formul));
    new Ajax.Updater(divi, php, {method: 'post', parameters: params});


    <div id="div1">
    contenido div1
    <form id="formulario" method="POST">
    <select size="3" id="lista" onchange="sendf('formulario', 'div2', 'prodiv1.php');">
    <option>elemento 1</option>
    <option>elemento 2</option>
    <option>elemento 3</option>
    <input type="button" id="b1" value="bot1" onclick="sendf('formulario', 'div2', 'prodiv1.php');" />
    <input type="button" id="b2" value="bot2" onclick="sendf('formulario', 'div2', 'prodiv1.php');" />

    <div id="div2" style="background: blue;">
    contenido div2

    file: prodiv1.php
    echo 'exec: prodiv1.php<br>';

    echo "select: ".$_POST['lista'];

    if (isset($_POST['b1'])) {echo 'click: boton1';} else {echo 'click: boton2';}

    doesnt work, and i dont know what to do next!
    any elegant solutions???
    thanks again!!!

  2. #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    London, UK
    Thanked 110 Times in 109 Posts
    "Doesn't work"....

    It would be handy if you could explain a little more about what doesn't work. Do you see an error message? Does something happen that shouldn't? Does something not happen that should?

    In any case, Firebug is your friend here. Use it to see exactly what, if anything, is being sent back and forth between the browser and the server.

  3. #3
    New to the CF scene
    Join Date
    Dec 2009
    Thanked 0 Times in 0 Posts
    it works now.
    i didnt see the list selection.
    it was just i forgot giving it a name. drove me mad!!
    thanx, anyway.


Posting Permissions

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