1

I have a form:

<form  name="green" class="form-inline" onchange="javascript:send_choose()" enctype="multipart/form-data">
<br><br>
  <div>
      <input type="text" class="form-control" style="width:100%;" name="linkgreen" id="linkgreen" placeholder="some example"> <br> <br>
  </div>
</form>

And JS in the bottom:

<script language="JavaScript" type="text/javascript" src="js/jquery-1.11.1.min.js"> 
function send_choose() {
    event.preventDefault();
    var link = document.getElementById('linkgreen');
    $.ajax({
        type: 'POST',
        url: 'include/create_file.php',
        data: {
            name4: 'weblink.txt',
            link: link.value
        },
    });
    $('input[type="text"]').attr('disabled', 'disabled');
    $('input[type="submit"]').attr('disabled', 'disabled');
};
$(document).ready(function () {});
</script>

It perfectly works in Chrome and IE and doesn't work in Mozilla.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • This isn't the issue, but get rid of the `javascript:`. It has no usefulness there. Also get rid of `language="JavaScript"`. –  Nov 13 '14 at 22:07
  • Do you have any error messages in your firefox developer toolbar? – rapsli Nov 13 '14 at 22:08
  • 7
    Your issue is that you have code inside a script that is importing an external file. This is wrong. Use 2 separate ` –  Nov 13 '14 at 22:08
  • no error messages in debugger of firefox. –  Nov 13 '14 at 22:11
  • But this code is work proper in Chrome and IE. –  Nov 13 '14 at 22:12
  • 4
    Another issue is that you're trying to use a global `event` object, which doesn't exist in Firefox. You need to pass it from the handler `onchange="send_choose(event)"` and receive it in the function `function send_choose(event){` –  Nov 13 '14 at 22:13
  • 1
    @inno.vlad When something works properly in one or more browsers does not mean that it is correct. Those browsers might just not care about that invalid syntax. – t.niese Nov 13 '14 at 22:14
  • 1
    @squint is right. Here is a [relevant question](http://stackoverflow.com/questions/4585970/jquery-event-preventdefault-not-working-in-firefox-jsfiddle-included) regarding why that is. – aug Nov 13 '14 at 22:21
  • @squint. IT WORKS!! Thank you! Exactly as you said: pass to handler and recive in function (event). Great. –  Nov 13 '14 at 22:32
  • also, you're using jquery. So why not `$('#linkgreen').val()` instead of `document.getElementById('linkgreen')` and using `.value` on it later? or adding an event listener instead of inline js? – Kai Qing Nov 13 '14 at 22:34
  • @KaiQing I'm just starting coding. First steps only. I have to learn a lot. –  Nov 13 '14 at 22:36
  • no problem. but those little bits of info will spare you a lot of trouble. – Kai Qing Nov 13 '14 at 23:04

1 Answers1

0

Try this, it separates the jquery include <script> tag and the <script tag for your code, which is the proper way to do things, what you did never works:

<script language="JavaScript" type="text/javascript" src="js/jquery-1.11.1.min.js"></script>
<script> 
function send_choose() {
    event.preventDefault();
    var link = document.getElementById('linkgreen');
    $.ajax({
        type: 'POST',
        url: 'include/create_file.php',
        data: {
            name4: 'weblink.txt',
            link: link.value
        },
    });
    $('input[type="text"]').attr('disabled', 'disabled');
    $('input[type="submit"]').attr('disabled', 'disabled');
};
$(document).ready(function () {});
</script>
erikvold
  • 15,988
  • 11
  • 54
  • 98