Reputation: 981
I am building a tool to help me assemble different keyword combinations for AdWords. I have a simple form with three checkboxes, an input box (for the starting keyword), a submit button and a textarea for the results (the variations on the input).
The first time around it works great, my conditionals are all working and I can run off a series of keywords that, on each .submit()
, will populate the textarea. The problem comes when I erase the contents. Here is an example of how it is populated:
if($("#phrase").is(":checked")) {
//Get keywords from input
var text = $("#keyword").val();
//Prepend and append double-quotes
text = "\"" + text + "\"";
//Output
var val = $("#output").val();
$("#output").append(text + "\r\n");
}
When I submit, I know it's still executing somewhere in my .submit()
function because if I uncheck all of the boxes my alert
(not shown) gets thrown.
Thinking it was something I was missing in the logic of my reset, I removed the reset entirely and posted it to my personal site so I could start working. I ran off some keywords, then manually deleted the contents of the textbox. Strangely, the same thing is still happening: after erasing/clearing the textbox, I can't get it to take the keyword and create any more variations!
I have created a fiddle here: Keyword Variations Fiddle -- I'm able to recreate the issue and have no idea why it's happening. Try deleting the text after you've generated a few keywords and then try to generate a few more.
Upvotes: 0
Views: 1633
Reputation: 1443
Interesting issue. I was concerned about your use of append
on the textarea since I remembered hearing that textareas were more like text inputs than divs so I tried using val
instead, and it worked fine.
And here's the relevant code.
//Output
var $output = $("#output");
var val = $output.val();
$output.val(val + text + "\n");
Upvotes: 5