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
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 ?

 

 

 

 

Link to comment
Share on other sites

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);
    
}

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.