You are viewing our Forum Archives. To view or take place in current topics click here.
(SOLVED) Help with Javascript code please?
Posted:

(SOLVED) Help with Javascript code please?Posted:

PoisonOak
  • Resident Elite
Status: Offline
Joined: Mar 29, 201212Year Member
Posts: 248
Reputation Power: 11
Status: Offline
Joined: Mar 29, 201212Year Member
Posts: 248
Reputation Power: 11
This is driving me crazy.


function oneButtonClickHandler(eventInfo) {
        var textbox = document.getElementById('numberInput');
        textbox.value = textbox.value && "1";
    }


All that happens when i click the button is that the textbox's value is changed to "1".
i want it to add the "1" to the current value. So if the textbox's value is "1234", then i want the value to be "12341". Any ideas?


Last edited by PoisonOak ; edited 1 time in total
#2. Posted:
Piracy
  • New Member
Status: Offline
Joined: Sep 10, 201211Year Member
Posts: 29
Reputation Power: 1
Status: Offline
Joined: Sep 10, 201211Year Member
Posts: 29
Reputation Power: 1
Try using this JavaScript, it should work, you don't use && to add something to the end of a value.

      function oneButtonClickHandler() // Your "eventInfo" was not needed
      {
         var textbox = document.getElementById("numberInput");
         textbox.value = textbox.value + 1;
      }
#3. Posted:
PoisonOak
  • Resident Elite
Status: Offline
Joined: Mar 29, 201212Year Member
Posts: 248
Reputation Power: 11
Status: Offline
Joined: Mar 29, 201212Year Member
Posts: 248
Reputation Power: 11
Piracy wrote Try using this JavaScript, it should work, you don't use && to add something to the end of a value.

      function oneButtonClickHandler() // Your "eventInfo" was not needed
      {
         var textbox = document.getElementById("numberInput");
         textbox.value = textbox.value + 1;
      }


Finally, thank you so much. I'm kinda new to JS and didn't know what to use to show two values. And i didn't know the event info wasn't needed. This is for a Windows 8 app so i just left if there.
#4. Posted:
Piracy
  • New Member
Status: Offline
Joined: Sep 10, 201211Year Member
Posts: 29
Reputation Power: 1
Status: Offline
Joined: Sep 10, 201211Year Member
Posts: 29
Reputation Power: 1
PoisonOak wrote
Piracy wrote Try using this JavaScript, it should work, you don't use && to add something to the end of a value.

      function oneButtonClickHandler() // Your "eventInfo" was not needed
      {
         var textbox = document.getElementById("numberInput");
         textbox.value = textbox.value + 1;
      }


Finally, thank you so much. I'm kinda new to JS and didn't know what to use to show two values. And i didn't know the event info wasn't needed. This is for a Windows 8 app so i just left if there.


No, the only time something goes in the parentheses is if you want variables to be inserted when you submit it.

Example:
function oneButtonClickHandler(eventInfo) // Your "eventInfo" was not needed
{
   var textbox = document.getElementById("numberInput");
   textbox.value = textbox.value + eventInfo; // Adds whatever was supplied in the event info
}


Now when you would want something for event info, so whatever you are using to submit this, such as a button, would be like:
<button onclick="oneButtonClickHandler('X');">+X</button>
<button onclick="oneButtonClickHandler('1');">+1</button>
<button onclick="oneButtonClickHandler('Awesome');">+Awesome</button>
#5. Posted:
PoisonOak
  • Resident Elite
Status: Offline
Joined: Mar 29, 201212Year Member
Posts: 248
Reputation Power: 11
Status: Offline
Joined: Mar 29, 201212Year Member
Posts: 248
Reputation Power: 11
Piracy wrote
PoisonOak wrote
Piracy wrote Try using this JavaScript, it should work, you don't use && to add something to the end of a value.

      function oneButtonClickHandler() // Your "eventInfo" was not needed
      {
         var textbox = document.getElementById("numberInput");
         textbox.value = textbox.value + 1;
      }


Finally, thank you so much. I'm kinda new to JS and didn't know what to use to show two values. And i didn't know the event info wasn't needed. This is for a Windows 8 app so i just left if there.


No, the only time something goes in the parentheses is if you want variables to be inserted when you submit it.

Example:
function oneButtonClickHandler(eventInfo) // Your "eventInfo" was not needed
{
   var textbox = document.getElementById("numberInput");
   textbox.value = textbox.value + eventInfo; // Adds whatever was supplied in the event info
}


Now when you would want something for event info, so whatever you are using to submit this, such as a button, would be like:
<button onclick="oneButtonClickHandler('X');">+X</button>
<button onclick="oneButtonClickHandler('1');">+1</button>
<button onclick="oneButtonClickHandler('Awesome');">+Awesome</button>

I see. Thank you for the help sir.
#6. Posted:
Piracy
  • New Member
Status: Offline
Joined: Sep 10, 201211Year Member
Posts: 29
Reputation Power: 1
Status: Offline
Joined: Sep 10, 201211Year Member
Posts: 29
Reputation Power: 1
PoisonOak wrote
Piracy wrote
PoisonOak wrote
Piracy wrote Try using this JavaScript, it should work, you don't use && to add something to the end of a value.

      function oneButtonClickHandler() // Your "eventInfo" was not needed
      {
         var textbox = document.getElementById("numberInput");
         textbox.value = textbox.value + 1;
      }


Finally, thank you so much. I'm kinda new to JS and didn't know what to use to show two values. And i didn't know the event info wasn't needed. This is for a Windows 8 app so i just left if there.


No, the only time something goes in the parentheses is if you want variables to be inserted when you submit it.

Example:
function oneButtonClickHandler(eventInfo) // Your "eventInfo" was not needed
{
   var textbox = document.getElementById("numberInput");
   textbox.value = textbox.value + eventInfo; // Adds whatever was supplied in the event info
}


Now when you would want something for event info, so whatever you are using to submit this, such as a button, would be like:
<button onclick="oneButtonClickHandler('X');">+X</button>
<button onclick="oneButtonClickHandler('1');">+1</button>
<button onclick="oneButtonClickHandler('Awesome');">+Awesome</button>

I see. Thank you for the help sir.


No problem. Happy to help.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.