Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2011-07-27 06:34:27

capdstuzz
New member
Registered: 2011-07-27
Posts: 1

My javascript only works in Chrome, not in i.e. nor in FF

Hello every1.
I'm getting this odd thing: as i have a form in which i need to set a title and a textarea (with xinha, obvious ;-) ), i need to check if the title field and the textarea are both empty.
So, i wrote this simple script:

$(document).ready(function() {
     


$("#ins_news").submit(function(){    
    testo = xinha_editors.areapress.getEditorContent();
//    testo = testo.replace(/<br \/>/, "");
    //testo = $.trim(testo);
    titolo = ins_news.titolo.value;
    if(testo == "" || titolo.length == 0)
    {
        alert("Bisogna inserire titolo e corpo del messaggio!");
        return false;
    } else 
    {
        if(ins_news.id.value!="") {
            
            id = ins_news.id.value;
            var dataString = 'titolo='+ titolo + '&areapress=' + testo + '&act=' + "edit" + '&id='+id;
            
        } else var dataString = 'titolo='+ titolo + '&areapress=' + testo + '&act=' + "add";
        
     $.ajax({  
  type: "POST",  
  url: "ins_news.php",  
  data: dataString,  
  success: function() {  
    alert("Dati inviati!");
    alert(dataString);
    location.replace('comunicati.php');
  }  
});  
return false;  

    }
//    return true;
});


});

Which in Chrome works properly but... when i use it in i.e. (even in compatibilty mode) and in FireFox, it doesn't work and just refreshes the page.
Do i have to think i have made some mistake?
Thanks to everyone for this great great job.


P.s.: i want to make a little contribution to xinha project, i translated the ExtendedFileManager plugin in italian. Where i can send it?

UPDATE: the REAL odd thing, is that i put a simple

alert("ok");

after

   titolo = ins_news.titolo.value;

the alert doesn't show. If i put the alert just before, the alert shows. So i think that

   titolo = ins_news.titolo.value;

is blocking the script in a way i can't understand, since in Chrome works a charme. Any idea?

UPDATE 2: This is drivin' me crazy. In FireFox the behaviour is just like in the previous update but... in Explorer the alert doesn't show after

testo = xinha_editors.areapress.getEditorContent();

so i think that there could be a problem or it could be a bug... am i wrong?

Last edited by capdstuzz (2011-07-27 07:04:57)

Offline

#2 2011-08-04 21:36:21

gogo
Xinha Leader
From: New Zealand
Registered: 2005-02-11
Posts: 1,015
Website

Re: My javascript only works in Chrome, not in i.e. nor in FF

$("#ins_news").submit(function(){    
    testo = xinha_editors.areapress.getEditorContent();

    titolo = ins_news.titolo.value;

I see some likely problems straight away.

testo and titolo are not declared, so they are global variables, I doubt you want that.
ins_news is not declared, so it is a global variable, and possibly isn't defined at all!

For example, you should better have code like...

$("#ins_news").submit(function(){    
   var titolo, testo; 
   var ins_news = $('#ins_news');

    testo = xinha_editors.areapress.getEditorContent();
    titolo = ins_news.titolo.value;

James Sleeman

Offline

Board footer

Powered by FluxBB