All,

I'm trying to obtain the values from an external JavaScript using PHP -

In my index.php page I'm trying to obtain the value being passed in as such:

`<input type="hidden" name="imgSrcOrig" id="imgSrcOrig" value="<?php echo $_REQUEST['remote_sill']; ?>"/>``

However - in the JavaScript I need to pass into the hidden field above the name of the image located in myImg

Since this is trying to be obtained from an external JavaScript in PHP - what should the call so the image name value appears in the hidden field should be:

The JavaScript call is as such:

<script type="text/javascript" src="nextPrevious.js"></script>

A snippet of the JavaScript nextPrevious.js is a such:

// List image names without extension
var myImg = new Array(4)
myImg[0] = "image_sill_1";
myImg[1] = "sill_image_2";
myImg[2] = "image_sill_3";
myImg[3] = "shape_3_sill";
myImg[4] = "shape_4_sill";

// Tell browser where to find the image
myImgSrc = "sills/";

// Tell browser the type of file
myImgEnd = ".png"

var i = 0;

// Create function to load image
function loadImg() {
    document.imgSrcOrig.src = myImgSrc + myImg[i] + myImgEnd;
}
Member Avatar for diafol
<?php echo $_REQUEST['remote_sill']; ?>

I don't understand this. REQUEST can take a value from POST, GET or COOKIE with the name 'remote_sill'.

The loadImg() function seems to be creating the filename, but there's no code that runs it. How is it run?

Is there a real need for this to be both js AND php? I can't really get a grip on what you're trying to do, so perhaps I'm getting this all wrong - but my take is ditch the php and just use js - if this has a carousel type functionality.

OK - here's an example via the URL - I'm uploading an image to a page - and the image the user uploads is going into a sillouette - the external JavaScript <script type="text/javascript" src="nextPrevious.js"></script> is the remote_sill whose parameter name I'm trying to pass into the query string because right now I'm getting the image that one uploads e-mailed to me - but I also want e-mailed to me the sillouette image as well. All the processing of the e-mail is utilizing php
as is the upload mechanism.

[http://www.pinkcloud.com/custom_clock/submit.php?upload_message=image uploaded&upload_message_type=success&show_image=sample image1.jpg&remote_sill=](http://www.pinkcloud.com/custom_clock/submit.php?upload_message=image uploaded&upload_message_type=success&show_image=sample image1.jpg&remote_sill=)

All,

I made some progress with this - my question is in PHP is their a built-in variable - I can utilize to obtain the value of a CSS class item on my page - I tried using $_GLOBALS to obtain the value of imageOne which is the CSS class I am looking to obtain the value for:

<input type="hidden" name="imgSrcOrig" id="imgSrcOrig" value="<?php echo $_GLOBALS['imageOne']; ?>" />

Member Avatar for diafol

Having to resort to $_GLOBAL vars suggests something is wrong with your code. You can actually pick up the image name with $_GET from the url querystring.

Ok thanks that helps - since the JavaScript whose value I need to pass into the querystring is being called external which basicially has functionality so that different images are shown when a next or previous button is selected - what I need to do and know is how to pass the value of the image to the querystring as I need to use it further which I will then get via the PHP (like so <input type="hidden" name="imgSrcOrig" id="imgSrcOrig" value="<?php echo $_GET['imageOne']; ?>" />). Also I need the remote_sill value in the querystring to have the default value of image_sill as such in the querystring upon first load.

So the external JavaScript is called like this in the page:

<script type="text/javascript" src="nextPrevious.js"></script>

In the HTML - of the previous and next buttons - I tried to pass the value as such with no luck:

<a href="#" onclick="prev()?remote_sill='+document.imgSrcOrig.src';"><img src="back.jpg" border="0" /></a>
<a href="#" onclick="next()?remote_sill='+document.imgSrcOrig.src';"><img src="next.jpg" border="0" /></a>    

Here is the full nextPrevious.js code:

// List image names without extension
var myImg = new Array(4)
myImg[0] = "image_sill";
myImg[1] = "sill_image";
myImg[2] = "image_sill";
myImg[3] = "shape_3_still";
myImg[4] = "shape_sill";

// Tell browser where to find the image
myImgSrc = "sills/";

// Tell browser the type of file
myImgEnd = ".png"

var i = 0;

// Create function to load image
function loadImg() {
    document.imgSrcOrig.src = myImgSrc + myImg[i] + myImgEnd;
}

// Create link function to switch image backward
function prev() {
    if (i < 1) {
        var l = i
    } else {
        var l = i -= 1;
    }
    document.imgSrcOrig.src = myImgSrc + myImg[l] + myImgEnd;
}

// Create link function to switch image forward
function next() {
    if (i > 2) {
        var l = i
    } else {
        var l = i += 1;
    }
    document.imgSrcOrig.src = myImgSrc + myImg[l] + myImgEnd;
}

// Load function after page loads
window.onload = loadImg;

To get the value from a hidden field into my mail script using PHP getting the hidden field value would be as such - correct:
$img1 = $_POST['hidimgSrcOrig'];

I'm not getting my hidden image in the e-mail using the above.
The HTML looks as such:
<input type="hidden" name="hidimgSrcOrig" id="hidimgSrcOrig" />

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.