Jump to content

GET src value from IMG tag by id


wcastro

Recommended Posts

Hello, I must to create a form system that will send an e-mail including an image that as show in site screen.

without the user must to write img name.

So I must to get the src value, and put in a hidden field.

 

But how to get the SRC value of img tag? I have a absolute ID for img tag that is 'jg_photo_big'

 

I need help just to get the value in a variable.

 

Cna anyone help some newbie ?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/253250-get-src-value-from-img-tag-by-id/
Share on other sites

I trying with JavaScript but i have problem to get javascript varialble in php;

 

tryed this

 

<script type="text/javascript">
var tenso = getElementById('jg_photo_big').src;

</script>

<?php
$texto="<script>" . 'document.write(\'tenso\');' ."</script>"; 
?>

 

 

and so

 

<input name="<?php echo $field->name; ?>" id="<?php echo $field->name; ?>" type="hidden" value="<?php echo $texto; ?>" />

 

But returns

 

<input name="fotomocada" id="fotomocada" type="hidden" value="<script>document.write('tenso');</script>">

 

I have no more ideas, anyone can help me ?

 

 

 

 

do you mean something like this

$img="../images/yourimagesrc.jpg";

<input type="hidden" value="<img src='<?php echo $img"'>

 

then send an email

 

<?php

// Example 

$HTML         = "<b><img src='$img'></b>";
$from         = "someone@someone";
$to           = "the_person_your_sending_to@yahoo.com";
$subject     = "Subject ";

sendHTMLemail($HTML,$from,$to,$subject);


function sendHTMLemail($HTML,$from,$to,$subject)
{
// First we have to build our email headers
// Set out "from" address

    $headers = "From: $from\r\n"; 

// Now we specify our MIME version

    $headers .= "MIME-Version: 1.0\r\n"; 

// Create a boundary so we know where to look for
// the start of the data

    $boundary = uniqid("HTMLEMAIL"); 
    
// First we be nice and send a non-html version of our email
    
    $headers .= "Content-Type: multipart/alternative;".
                "boundary = $boundary\r\n\r\n"; 

    $headers .= "This is a MIME encoded message.\r\n\r\n"; 

    $headers .= "--$boundary\r\n".
                "Content-Type: text/plain; charset=ISO-8859-1\r\n".
                "Content-Transfer-Encoding: base64\r\n\r\n"; 
                
    $headers .= chunk_split(base64_encode(strip_tags($HTML))); 

// Now we attach the HTML version

    $headers .= "--$boundary\r\n".
                "Content-Type: text/html; charset=ISO-8859-1\r\n".
                "Content-Transfer-Encoding: base64\r\n\r\n"; 
                
    $headers .= chunk_split(base64_encode($HTML)); 

// And then send the email ....

    mail($to,$subject,"",$headers);
    
}

?>

SOLVED!

 

Sharing:

First

<input name="<?php echo $field->name; ?>" id="hidden_imagem" type="hidden" value="" />
<img src="images/foto1.jpg" id="jg_photo_big" />

 

Then

<script type="text/javascript">
document.getElementById('hidden_imagem').value = document.getElementById('jg_photo_big').src;
</script>

 

Is important that javacode came after the element, otherwise will generate error.

 

Thanks anyway

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.