0

I have a bookmarklet:

var b=document.getElementsByClassName('textinput')[0];
b.value=' (Christiansburg)';
var f=document.createEvent("HTMLEvents");
f.initEvent('change',true,true);
b.dispatchEvent(f);
void(0);

This replaces the content (if any) of the Title of a Google Calendar event with (Christiansburg). I would like for it to instead just append it to whatever content is already there. I've tried a couple of things but I can't figure out how to get it to work.

Jonathan M
  • 17,145
  • 9
  • 58
  • 91
aslum
  • 11,774
  • 16
  • 49
  • 70

4 Answers4

4

Replace the = operator

b.value  = ' (Christiansburg)';

to the += operator which will append your string to the value:

b.value += ' (Christiansburg)';
biziclop
  • 14,466
  • 3
  • 49
  • 65
1

b.value += 'yourtextgoesrighthere'; will do it. The '+' sign is an append operator if used on a string.

Lusitanian
  • 11,012
  • 1
  • 41
  • 38
1

To append a string value to an existing string, you may use the += operator for the assignment:

b.value += ' (Christiansburg)';
Eliran Malka
  • 15,821
  • 6
  • 77
  • 100
1

you can append strings with the + operator. so "Hello" + " " + "world" would be "Hello world".

So you could do b.value = b.value + ' (Christiansburg)';

Since appending is done quite often, there is a shorthand: b.value += ' (Christiansburg)'

DZittersteyn
  • 628
  • 3
  • 8