I'm trying to load an image (created with PHP) with jQuery and passing a few variables with it (for example: picture.php?user=1&type=2&color=64). That's the easy part.
The hard part is that I've a dropdown which enables me to select background (the type parameter) and I'll have an input for example to select a color.
Here're the problems I'm facing:
- If a dropdown/input hasn't been touched, I want to leave it out of the URL.
- If a dropdown/input has been touched, I want to include it in the url. (This won't work by just adding a variable "&type=2" to the pre-existing string as if I touch the dropdown/input several times they'll stack (&type=2&type=2&type=3)).
- When adding a variable ("&type=2" - see the code below) to the pre-existing URL, the &-sign disappears (it becomes like this: "signature.php?user=1type=2").
Here's the code for the jQuery:
<script>
    var url = "signatureload.php?user=<?php echo $_SESSION['sess_id']; ?>";
    $(document).ready(function() {
        window.setTimeout(LoadSignature, 1500);
    });
    $("#signature_type").change(function() {
        url += "&type="+$(this).val();
        LoadSignature();
    });
    function LoadSignature()
    {
        $("#loadingsignature").css("display", "block");
        $('#loadsignature').delay(4750).load(url, function() {
            $("#loadingsignature").css("display", "none");
        });
    }
</script>
Here's the code where I load the image:
<div id="loadsignature">
    <div id="loadingsignature" style="display: block;"><img src="img/loading-black.gif" alt="Loading.."></div>
</div>
I don't know how more further I could explain my problem. If you have any doubts or need more code, please let me know.
Thank you for your help!
EDIT:
Here's the current code:
<script>
    var url = "signatureload.php?user=<?php echo $_SESSION['sess_id']; ?>";
    $(document).ready(function() {
        window.setTimeout(LoadSignature, 1500);
    });
    $("#signature_type").change(function() {
        url = updateQueryStringParameter(url, 'type', $(this).val());
        LoadSignature();
    });
    function LoadSignature()
    {
        $("#loadingsignature").css("display", "block");
        $('#loadsignature').delay(4750).load(url, function() {
            $("#loadingsignature").css("display", "none");
        });
    }
    function updateQueryStringParameter(uri, key, value)
    {
        var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i"),
        separator = uri.indexOf('?') !== -1 ? "&" : "?",
        returnUri = '';
        if (uri.match(re))
        {
            returnUri = uri.replace(re, '$1' + key + "=" + value + '$2');
        }
        else
        {
            returnUri = uri + separator + key + "=" + value;
        }
        return returnUri;
    }
</script>
EDIT2:
Here's the code for signatureload.php
<?php
    $url = "signature.php?";
    $count = 0;
    foreach($_GET as $key => $value)
    {
        if($count > 0) $url .= "&";
        $url .= "{$key}={$value}";
    }
    echo "<img src='{$url}'></img>";
?>
 
     
     
     
     
    