Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Pobieranie danych z klikniecia w obrazek ajax
teez
post
Post #1





Grupa: Zarejestrowani
Postów: 186
Pomógł: 6
Dołączył: 20.12.2010

Ostrzeżenie: (0%)
-----


Witam,

Chciałbym się dowiedzieć w jaki sposób pobierane jest ID z takiego wyboru jak tu:

  1. <script type='text/javascript' src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  2.  
  3. <form action="here" method="post">
  4. <div id="sMale" style="display:none;">
  5.  
  6.  
  7. <img src="{$this->settings['public_dir']}gp/skins/2.png" class="skins" id="2" style="margin-top: 3px;" />
  8. <img src="{$this->settings['public_dir']}gp/skins/2.png" class="skins" id="3" style="margin-top: 3px;" />
  9. <img src="{$this->settings['public_dir']}gp/skins/2.png" class="skins" id="4" style="margin-top: 3px;" /></div>
  10. <input type="hidden" name="skin" id="sid" value=""><br />
  11. <div align="center"><input type='submit' class='input_submit' value='Submit' /></div>
  12.  
  13. </form>
  14. <script type="text/javascript">
  15. jQuery(".skins").click( function () { if( jQuery("#sid").val() != jQuery(this).attr("id")){ jQuery(".skins").fadeTo("fast", 0.33); jQuery(this).fadeTo("fast", 1); jQuery("#sid").val( jQuery(this).attr("id") ); } else { jQuery(".skins").fadeTo("slow", 1); jQuery("#sid").val(""); } });
  16.  
  17. jQuery("#charsex").change( function () { if(jQuery(this).val() == '1') { jQuery("#sMale").show("slow"); jQuery("#sFemale").hide("slow"); } else if (jQuery(this).val() == '0') { jQuery("#sFemale").show("slow"); jQuery("#sMale").hide("slow"); } else { jQuery("#sMale").hide("slow"); jQuery("#sFemale").hide("slow"); } });
  18. </script>
  19.  



W jaki sposób mogę pobrać jaki 'id' został wybrany?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
teez
post
Post #2





Grupa: Zarejestrowani
Postów: 186
Pomógł: 6
Dołączył: 20.12.2010

Ostrzeżenie: (0%)
-----


Ok, mam w konsoli firebuga odpowiedź:

Kod
http://localhost/f/index.php?app=gp&module=createchar&id=20


Ale.. Nie mogę tego odczytać w PHP po wysłaniu formularza ( action=[...]createchar ), poneiważ wtedy get['id'] sie zeruje.

Ktoś moze podpowiedzieć? Nie mam kompletnie pojęcia jak to zrobić. Ładuje mi się wszystko OK w konsoli, ale po wysłaniu formularza jest form action="plik.php" i tam wysyła, więc zeruje ten get..

Próbuję na czystym kodzie:

Kod
<HEAD>
<TITLE> TEST </TITLE>
<script type='text/javascript' src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>

</HEAD>

<form action="index.php" method="post">
    <table class="ipb_table">
        <tbody>
        <tr class="header">
        </tr>
        <tr>
            <td width="42%" align="right"><strong>Imię</strong></td>
            <td align="left"><input type="text" class="input_text" name="imie" size="25" maxlength="24" placeholder="Martin"></td>
        </tr>
        <tr>
            <td width="42%" align="right"><strong>Nazwisko</strong></td>
            <td align="left"><input type="text" class="input_text" name="nazwisko" size="25" maxlength="24" placeholder="Diesel"></td>
        </tr>
        <tr>
            <td align="right"><strong>Wiek</strong></td>
            <td align="left"><input type="text" class="input_text" name="charage" size="25" maxlength="4" placeholder="21 lat"></td>
        </tr>
        <tr>
            <td align="right"><strong>Płeć</strong></td>
            <td align="left">
                <select id="charsex" name="charsex" class="input_text" style="min-width: 158px;">
                    <option value="-1" selected="selected"> </option>
                    <option value="1">Mężczyzna</option>
                    <option value="0">Kobieta</option>
                </select>
            </td>
        </tr>
        </tbody>
    </table>
        
        
<div id="sMale" style="display:none;">
        
            
            <img src="http://localhost/f/public/gp/skins/2.png" class="skins" id="2" style="margin-top: 3px;" />

            <img src="http://localhost/f/public/gp/skins/7.png" class="skins" id="7" style="margin-top: 3px;" />

            
    </div>

    <div id="sFemale" style="display:none;">
        

            <img src="http://localhost/f/public/gp/skins/9.png" class="skins" id="9" style="margin-top: 3px;" />

            <img src="http://localhost/f/public/gp/skins/12.png" class="skins" id="12" style="margin-top: 3px;" />

    </div>
            
            
    <input type="hidden" name="skin" id="sid" value=""><br />
    <div align="center"><input type='submit' class='input_submit' value='Submit' /></div>

</form>
<script type="text/javascript">
jQuery(".skins").click( function () { if( jQuery("#sid").val() != jQuery(this).attr("id")){ jQuery(".skins").fadeTo("fast", 0.33); jQuery(this).fadeTo("fast", 1); jQuery("#sid").val( jQuery(this).attr("id") ); } else { jQuery(".skins").fadeTo("slow", 1); jQuery("#sid").val(""); } });
jQuery("#charsex").change( function () { if(jQuery(this).val() == '1') { jQuery("#sMale").show("slow"); jQuery("#sFemale").hide("slow"); } else if (jQuery(this).val() == '0') { jQuery("#sFemale").show("slow"); jQuery("#sMale").hide("slow"); } else { jQuery("#sMale").hide("slow"); jQuery("#sFemale").hide("slow"); } });

$('.skins').click(function(event) {
$.post('index.php', {'id' : $(this).attr('id')}, function(data) {

})
});

</script>
<?php

        echo $_POST['id'];
                echo "<br/>";
        echo $_POST['imie'];
                echo "<br/>";
        echo $_POST['nazwisko'];
                echo "<br/>";
        echo $_POST['charage'];
                echo "<br/>";
        exit();

?>


Próbowałem i getem i postem to wysyłać.. Nie wysyła nic..

Ten post edytował teez 7.04.2013, 21:22:50
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 28.12.2025 - 14:24