-3

I can usually Google and find my answer, but I have no idea with this issue on where to even start. If someone could point me in the right direction here as to what language and syntax is being used here, I'd appreciate it.

This is saying "if input1 = 'option1', then output text1 into span1 and if not, input text2.

I'm sorry this is so basic, but need to learn how to edit this but I'm lost without a tutorial or guide.

$('#span1').html(input1='option1'?'text1':'text2');

This is kind of a repost from an earlier question I had where I was accused of trying to get free coding advice so I've made this as basic as possible. I'm not looking for free coding here - if someone could give me a hint as to where I could find more information, I'd appreciate it.

Cameron Hurd
  • 4,836
  • 1
  • 22
  • 31
user2554201
  • 33
  • 1
  • 8
  • 1
    This is javascript and probably jquery library. Also using `=` instead of `==` leads to unforseen consequences. – u_mulder Oct 31 '17 at 16:40

2 Answers2

0

This is a snippet of jQuery - a javascript framework.

$('#span1').html(input1='option1'?'text1':'text2');
  • $ This is the jQuery "object", and passing a selector argument to it will return a jQuery-wrapped object that you can chain methods to.

  • #span1 selector argument (may as well be CSS)

  • input1='option1'?'text1':'text2' Will output "text1" or "text2" depending on wether or not the variable option1 evaluates to true. It's very likely, as u_mulder points out, that this is going to fail. Use two == or three === for comparisons!

  • html(...) The html method chained onto the output of the selector accepts the new value to write to that element's contents in the DOM.

Suggested reading:

Cameron Hurd
  • 4,836
  • 1
  • 22
  • 31
  • Maybe you didn't notice but `input1='option1'` means `assign option1 to input1`. – u_mulder Oct 31 '17 at 16:44
  • Thanks, Mulder, I'll work with what the user likely meant for the code to do. – Cameron Hurd Oct 31 '17 at 16:44
  • Ok, so this is JQuery, that helps. I'll try to find a tutorial on this. My code assumes only 2 options. I need to learn the syntax when there are more than 2 options. – user2554201 Oct 31 '17 at 17:55
  • 1
    Check my suggested reading for some links to explain what's going on. And if it's sufficiently answered your question, please upvote & accept my answer! – Cameron Hurd Oct 31 '17 at 17:56
0

Was able to do it not using that code but a code I'm more familiar with like this:

if(pay_type == 'onetime') {
   $('#bank_card_pay_type').html('one time payment');
 }
 else if(pay_type == 'montly') {
   $('#bank_card_pay_type').html('3 monthly payments');
 }
 else if(pay_type == 'monthly12') {
   $('#bank_card_pay_type').html('12 monthly payments');
 }
user2554201
  • 33
  • 1
  • 8