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>

Recommended Answers

All 8 Replies

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

Member Avatar for iamthwee

if($.trim -line 14

^^remove the $.

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.

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

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?

Yes it won't submit

on the console it says ok

`Status Code:   HTTP/1.1 200 OK`
Member Avatar for iamthwee

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

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.