0

Does anybody sees a fault in this?

both codes are in the same file. It seems it doesnt gets in the javascript/ajax script because the alert doesnt work but i cant figure out why?

 <form method="post" enctype="text/plain"> 
<textarea name="update_press" id="update_press"></textarea>
<input type="submit" name="press_button" class="press_button" id="press_button" value="Submit">
</form>



 <SCRIPT>
            $(".press_button").click(function() 
{
    var updateval = $("#update_press").val();

    var dataString = 'update_press='+ updateval;
    if($.trim(updateval).length==0)
    {
        alert("Please write a text");
    }
    else
    {
        $("#flash").show();
        $("#flash").fadeIn(400).html('Loading Update...');
        $.ajax(
        {
            type: "POST",
            url: "text_ajax.php",
            data: dataString,
            cache: false,
            success: function(html)
            {
                $("#update_press").val('').focus().css("height", "40px");
            }
        });
    }
    return false;
}); 
            </SCRIPT>
4
Contributors
8
Replies
50
Views
3 Years
Discussion Span
Last Post by iamthwee
0

When you open the page with your browser and look at the dev tools (F12), do you see any errors in the console log?

1

It's working fine here, after adding

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

above your script. Did you include jQuery on your page?

The $.trim() method is working as well, I get the alert when leaving the field blank and also after entering a series of whitespaces.

Word of warning, if you were to move your script to the header of the page (in other words, place the button below the script) the handler will not bind because the element doesn't exist yet at the time of execution. In that case you'd have to make sure the document is ready.

0

Jorge, my f12 isnt working is there another way? I am using firebug.
The thing is that i am using a simiral script elsewhere and it works fine. It doesnt go on the file i am calling the <script>, so i did what Traevel said i had the script before the form, now i put the js file

`<?php 
include_once 'js.php';
?>`

after the </form> Now the alert works but the button can't pressed

0

You could look at the firebug console by pressing the bug (F12 brings that one up for me). An alternative console could be ctrl-shift-j. Which button can't be pressed? You said the alert works, so that button is working then I take it. Do you mean it won't submit the form?

0

If you're using other js codes an issue could reside there. Concerning the question asked, you're doing nothing wrong on its own.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.