Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Need Help with adding to form

Featured Replies

Hey everyone. I have a form that has a plus button and a minus button on each side. I want the form to go up by three when clicked. Right now it goes up and down by one using the ++ operator. How can i get it to change to an value I need? Thanks, the code is below...

 

<script type="text/javascript">
function trim(str) {
 return str.replace(/^\s+|\s+$/g, '');
}


function isEmpty(str) {
 str = trim(str);
 return ((str == null) || (str.length == 0))
}


function isDigit(c) {
 return ((c >= "0") && (c <= "9"))
}


function isInteger(str) { 
 var i;
 for (i = 0; i < str.length; i++) {
 var c = str.charAt(i);
 if (!isDigit(c)) return false;
 }
 return true;
}


function monthModify(txtElement, btnElement) {

 switch(btnElement.name) {
case 'increase':
 	if(isEmpty(txtElement.value)) {
   	txtElement.value = '1';
 	} else if(isInteger(txtElement.value)){
   	txtElement.value ++;
 	} else {
   	alert('The value you are trying to increment is not an integer');
   	txtElement.value = '';
 	}
break;

case 'decrease':
 	if(isEmpty(txtElement.value)) {
   	txtElement.value = '0';
 	} else if(isInteger(txtElement.value)){
   	if(txtElement.value > 0) {
     	txtElement.value --;
   	} else {
     	alert('The minimum value is zero for this field');
   	}
 	} else {
   	alert('The value you are trying to decrement is not an integer');
   	txtElement.value = '';
 	}
break;

default:
 }
}

function initForm(oForm, element_name, init_txt) {
 frmElement = oForm.elements[element_name];
 frmElement.value = init_txt;
}

function showFormData(oForm) {
 var msg = "The data that you entered for the form : \n";

 for (i = 0; i < oForm.length, oForm.elements[i].getAttribute("type") !== 'button'; i++) {
msg += oForm.elements[i].tagName + " with 'name' attribute='" + oForm.elements[i].name + "' and data: ";
if(oForm.elements[i].value == null || oForm.elements[i].value == '') {
msg += "NOT SET \n";
} else {
 	msg += oForm.elements[i].value + "\n";
}
 }

 alert(msg);
}


function clearFieldFirstTime(element) {
 if (element.counter==undefined) {
 element.counter = 1;
 }

 else {
 element.counter++;
 }

 if (element.counter == 1) {
 element.value = '';
 }
}
</script>

Edited by Boyles Web Design

  • Author

Nevermind I got it to work with...

 


switch(btnElement.name) {
       case 'increase':
       if(isEmpty(txtElement.value)) {
       txtElement.value = '1';
       } else if(isInteger(txtElement.value)){
       txtElement.value -= -35;
       } else {
       alert('The value you are trying to increment is not an integer');
       txtElement.value = '';
       }
       break;

 

Where 35 is my incrament

Edited by Boyles Web Design

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.