wcastro Posted December 15, 2011 Share Posted December 15, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253250-get-src-value-from-img-tag-by-id/ Share on other sites More sharing options...
trq Posted December 15, 2011 Share Posted December 15, 2011 You would need to do this client side using JavaScript. Quote Link to comment https://forums.phpfreaks.com/topic/253250-get-src-value-from-img-tag-by-id/#findComment-1298263 Share on other sites More sharing options...
wcastro Posted December 16, 2011 Author Share Posted December 16, 2011 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/253250-get-src-value-from-img-tag-by-id/#findComment-1298501 Share on other sites More sharing options...
conan318 Posted December 16, 2011 Share Posted December 16, 2011 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 = "[email protected]"; $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); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/253250-get-src-value-from-img-tag-by-id/#findComment-1298504 Share on other sites More sharing options...
wcastro Posted December 16, 2011 Author Share Posted December 16, 2011 Yes, send by mail is not the problem. Is something like this, but 1st I need to get the image src value in a variable, from the img Tag Quote Link to comment https://forums.phpfreaks.com/topic/253250-get-src-value-from-img-tag-by-id/#findComment-1298506 Share on other sites More sharing options...
wcastro Posted December 16, 2011 Author Share Posted December 16, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253250-get-src-value-from-img-tag-by-id/#findComment-1298517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.