Alvaro
Alvaro

Reputation: 273

JQUERY load vs get

I have this line of code

$('#findemail').load('findemail.php', {id: this.id, tabla: $(this).attr("rel")});

which loads alright the data in the anchor div. However, it turns out that I need to utilize that data, namely it displays an email address and I need to "grab" that email address and send it through a "hidden submit" from the webform to the mail processing script. That line above is sending two parameters, the ID and the tablename, that are used by a SQL query, which selects me the email I want to use, in the form of $destination_email

Someone told me that in order to do that, I just need to use "get" instead of "load" like here below, but putting together that I am a bit retard and that I have about an hour "experience" with JQUERY I dont know how to benefit from that code. My webform is some hundreds of lines below in that same page, so I dont know how to fully finish that JQUERY code so that I can fetch it from my HTML form to forward it, as I said. Please, if you want to help dont just give me a hint, I still dont know the syntax of JQUERY although I am struggling to learn as much as I can. The code is nearly finished anyway.

The full code is here below. The first line does the load alright, it fills me a div box with that and that is all I need. But the second line, as I have explained, fetches an email address in the form of a variable, and I need to work with that, that is why it uses "get"

<script type="text/javascript"> 
$(document).ready(function(){
$('a.flip').live('click',function(){
    $(".panel").slideToggle("slow");


$('#reviews').load('SendIdToDatabase.php', {id: this.id, tabla: $(this).attr("rel")});



$.get('findemail.php', {id: 'findemail', tabla: $('#findemail').attr('rel')}, function(data) {
      // data contains the response
}); 



  });
});

</script>

UPDATE TO 99,99% FINISHED CODE

HERE is what I have. It seems fine to me, however, hm, still is not sending that email away

only below the dotted line is interesting, the rest works perfect. Below the dotted line is the code that fetches the email. It does load it perfect, it displays it so as if hardocoded on the surface of my HTML form as [email protected] but there probably is very minor thing impeding that to be passed on.

<script type="text/javascript"> 


$(document).ready(function(){
$('a.flip').live('click',function(){
    $(".panel").slideToggle("slow");


$('#reviews').load('SendIdToDatabase.php', {id: this.id, tabla: $(this).attr("rel")});
................................................................................


$('#findemail').load('findemail.php', 
                   {id: this.id, tabla: $(this).attr("rel")},
                   function() {
                     var email = $(this).find(".email").val();

                 });

          });


  });

</script>


<?php
echo '<div id ="findemail" class="email">';


echo '<input type="hidden" name = "country" class="email" value= "'.$destination_email.'"/>';

echo '</div>';
?>





<div id="form-submit"><input type="submit" id="submit-form" name="submit" value="Submit" /></div>
</form>

Grasping the idea from Nick

it can also be that the SQL query issues not just an email alone, but the whole

echo '"<input type = "hidden" val=\"' .addslashes($aRow['email']) .'\" class=\"email\" .>"';

=======================================================================================

So There seem to be 2 different solutions that you Brian and Nick are proposing:

NICKS

$('#findemail').load('findemail.php', 
                   {id: this.id, tabla: $(this).attr("rel")},
                   function() {
                     var email = $(this).find(".email").val();

AND THEN THIS:

<?php
echo '<div id ="findemail" class="email">';


echo '<input type="hidden" name = "country" class="email" value= "'.$destination_email.'"/>';

echo '</div>';
?>

AND THEN BRIANS:

var email = $('#reviews').html(); // this to grab the email

and here below embedded in my webform

but, is the syntax correct ? where is the start of the <input>?

$('#my-form').append($('<input/>').attr('type', 'hidden').val(email))

Upvotes: 0

Views: 1233

Answers (1)

Nick Craver
Nick Craver

Reputation: 630379

You can still get the data with .load(), if it was returned to load in your element, for example:

$('#reviews').load('findemail.php', 
                   {id: this.id, tabla: $(this).attr("rel")},
                   function() {
                     var email = $(this).find(".email").val();
                   });

The concept is pretty simple, if it's in the response, it was already loaded in the HTML of your #reviewsElement, so just grab it from wherever it was in there.

Upvotes: 1

Related Questions