0

First of all, apologies for the low level of Javascript I'm about to post. I just started playing around with it in my spare time last week to set something up to make my life at work easier.

In a nutshell, I work at a call centre. At the end of each call I have to enter notes into the system. I wanted to create a HTML page where I can simply click a few things and the notes will be ready for me to cut and paste. I'm now playing with drop down menus instead of a billion buttons.

I have a function that is triggered on a button press, which I'd like to then enter text into a textarea based on the selection from a drop down menu. For some reason (that I can't find an answer for), the text appears and then instantly disappears.

Here's my function:

function openCall() {
    var callerselection = document.fsnotes.caller.value;
    if (callerselection = "CH") {
        document.fsnotes.notesentry.value += "CH called ";
    }
}

Here's the Form:

<form name="fsnotes">
    <textarea rows="8" cols="50" name="notesentry"></textarea>
    </br>
    <select name="caller">
        <option>CH</option>
    </select>
    <button onClick="openCall()">OK</button>
</form>

Naturally I have a lot more in my main html file, I just have this smaller one to test new ideas in, as a lot of people in my department are now using the one with a billion buttons.

Sushil
  • 2,837
  • 4
  • 21
  • 29
Leon
  • 3
  • 1
  • Change `callerselection = "CH"` to `callerselection == "CH"` – Mark Leiber Jun 10 '15 at 18:27
  • Thanks Mark, tried that, still seems to appear in the textarea and then instantly disappear. This is in Chrome, doesn't appear to do anything at all in IE or Firefox. – Leon Jun 10 '15 at 18:37

1 Answers1

0

Your button is submitting your form.

Change the button to:

<button onClick="openCall(); return false;">OK</button>

Here's a jsfiddle: http://jsfiddle.net/9m5k5amh/3/

Also see: How to prevent buttons from submitting forms

Community
  • 1
  • 1
Mark Leiber
  • 3,118
  • 2
  • 13
  • 22