Javascript says function is not defined, when it is.

Discussion in 'JavaScript' started by boynedmaster, May 5, 2013.

  1. #1
    My javascript (Yes there's Jquery, but no I don't think that's why the error is here):
    <script src="http://code.jquery.com/jquery-2.0.0.js"/>
            <script>
                function updateDesc(){
                    //Get current description
                    var curDesc = "";
                   
                    $.ajax({
                        url: "desc.php",
                        type: "POST",
                        data: {'id': <?php echo $_SESSION['id']; ?>, 'op': 'get'},
                        dataType: "json",
                        success: function(d){
                            curDesc = d.desc;
                        }
                    });
                   
                    var descPrompt = prompt("Change description to:", curDesc);
                   
                    if(descPrompt){
                        $.ajax({
                            url: "desc.php",
                            type: "POST",
                            data: {'id': <?php echo $_SESSION['id']; ?>, 'to': descPrompt, 'op': 'update'},
                            dataType: "json"
                        });
                       
                        var go = confirm("Description changed! Go to profile?");
                       
                        if(go == true){
                            window.location = "myprofile.php";
                        }
                    }
                }
            </script>
    HTML:
    The console:
    The area in which line 76 is
    if(isset($_GET['error'])){
                    switch($_GET['error']){
                        case "user_exists":
                            ?>
                                <script>
                                    alert('Sorry! That user already exists!');
                                </script>
                            <?php
                            break;
                        case "wrong_captcha":
                            ?>
                                <script>
                                    alert('The captcha you entered is wrong!');
                                </script>
                            <?php
                            break;
                        case "shortuser":
                            ?>
                                <script>
                                    alert('Usernames need to be at least 6 characters!');
                                </script>
                            <?php
                            break;
                        case "shortpass":
                            ?>
                                <script>
                                    alert('Passwords need to be at least 6 characters!');
                                </script>
                            /*Line 76 */ <?php
                            break;
                        case "password":
                            ?>
                                <script>
                                    alert('Passwords do not match!');
                                </script>
                            <?php
                            break;
                        case "login":
                            ?>
                                <script>
                                    alert('Incorrect login!');
                                </script>
                            <?php
                            break;
                    }
                }
    PHP:
    BUT where I referenced doing the function:
     <input type="submit" value="Change description?" onclick="updateDesc()"><br> 
    HTML:

     
    boynedmaster, May 5, 2013 IP
  2. boynedmaster

    boynedmaster Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    Hello?
     
    boynedmaster, May 5, 2013 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    Well, first thing I see is this:
    <script src="http://code.jquery.com/jquery-2.0.0.js"/>

    SCRIPT is NOT an 'empty' tag by the specification, so you cannot make it XML style self closing. You MUST type </script>.

    I'm trying to make sense out of your code, and not having a whole lot of luck -- it's, well... gibberish or I'm just not seeing enough of it in your posts. I'm wondering why the devil you have PHP outputting alerts based on getData of all things...It's like you've got how PHP and Javascript work together confused, or worse you're using AJAX on something that shouldn't even be being sent server side yet!

    Though this also reeks of using pointless jquery+scripting with multiple AJAX submits via a bunch of annoying dialog boxes to do a static form's job.
     
    deathshadow, May 5, 2013 IP