payket
payket

Reputation: 137

javascript - unexpected token?

I want to add loading gif while uploading photos. Here is my JavaScript :

<script type="text/javascript">
    function call(tab) {
        $(".loading").html("<center><br><br><img src=\"icons/processing.gif\" /><br><br></center>").load(tab);

    }
</script>

This is how I call the function :

<div class="loading"></div>
    <div class="col-md-12">
        <div class="form-group">
            <input type="file" name="take_photo" id="take_photo" class="take-photo" onchange="submit(); call('survey_edit.php?id='<?$id;?>'&step=photo')">
            <label for="take_photo"><figure><img src="icons/camera.png"></figure> <span><?=v("take_photo");?>&hellip;</span></label>
        </div>
        <div class="form-group">
            <?=$f->input("back",v("back"),"type='button' onclick=\"window.location='?step=2&id=".$id."';\"","btn btn-warning");?>
            <?=$f->input("finish",v("finish"),"type='button' onclick=\"window.location='mysurvey.php';\" style='position:relative;float:right;'","btn btn-primary");?>
        </div>
    </div>

It shows the following error: "Uncaught SyntaxError: Unexpected token ? "

Can anyone help me with this?

Upvotes: 0

Views: 78

Answers (2)

t.niese
t.niese

Reputation: 40852

Base on the comment the problem was with this line:

<input type="file" name="take_photo" id="take_photo" class="take-photo" onchange="submit(); call('survey_edit.php?id='<?$id;?>'&step=photo')">

The problem here is that the ' right before the <? will end the string in js, and <? should be <?=, because otherwise <?$i?> would not be replace by php with the value of $i.

So then the string is compared (<) with ? and that ? is then a unexpected token.

<input type="file" name="take_photo" id="take_photo" class="take-photo" onchange="submit(); call('survey_edit.php?id=<?=$id;?>&step=photo')">

Upvotes: 1

Alexander Fedoseev
Alexander Fedoseev

Reputation: 101

You event of onchange should be looking like this:

onchange="submit(); call('survey_edit.php?id=<?=$id?>&step=photo')"

Upvotes: 1

Related Questions