Author Topic: Regular Expression help?  (Read 4747 times)

Offline wortman72

  • Newbie
  • *
  • Posts: 11
  • Karma: +1/-0
    • View Profile
Regular Expression help?
« on: June 09, 2015, 10:14:06 AM »
I have very little background in web development, so I'm hoping someone can walk me through setting up a regular expression for one of my products.

The product has 2 options defined by dropdown menus, each is a 2 digit number. I would like to make a regular expression to ensure the larger number is chosen first, since pricing is based off of the larger number.

For example:

Option1 = 65
Option2 = 45
is a valid option combination

Option1 = 45
Option2 = 75
is not valid.

Seems like this should be pretty straightforward if I knew anything about javascript!  ;)  Can someone help me out with some example code? Thanks in advance.

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1945
  • Karma: +298/-12
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Regular Expression help?
« Reply #1 on: June 09, 2015, 10:34:14 AM »
your trouble is not related ot regexp.
You can solve it by custom javascript. for ex:
Code: [Select]
<script >
if($('#option1_id').val()<$('#option2_id').val()){
       alert('You cannot choose option2 value greater then option1!');
}
</script>
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline wortman72

  • Newbie
  • *
  • Posts: 11
  • Karma: +1/-0
    • View Profile
Re: Regular Expression help?
« Reply #2 on: June 09, 2015, 11:39:07 AM »
I've tracked down the option id's as option354 and option355, Now where would I put this code?

Thanks for your help!

Offline wortman72

  • Newbie
  • *
  • Posts: 11
  • Karma: +1/-0
    • View Profile
Re: Regular Expression help?
« Reply #3 on: June 10, 2015, 08:55:14 AM »
abolabo, can I get a little more help on where to put the js code?

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1945
  • Karma: +298/-12
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Regular Expression help?
« Reply #4 on: June 10, 2015, 10:55:18 AM »
I've tracked down the option id's as option354 and option355, Now where would I put this code?

Thanks for your help!

just replace option1_id by option354 and option2_id by option355 in given code
Code: [Select]
<script >
if($('#option354').val()<$('#option355').val()){
       alert('You cannot choose option2 value greater then option1!');
}
</script>
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline wortman72

  • Newbie
  • *
  • Posts: 11
  • Karma: +1/-0
    • View Profile
Re: Regular Expression help?
« Reply #5 on: June 10, 2015, 11:49:06 AM »
I understand the script itself, I just need to know what file to add it to. Does it need to be edited into a php file somewhere? or is there space for custom javascript in my admin page somewhere?

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1945
  • Karma: +298/-12
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Regular Expression help?
« Reply #6 on: June 10, 2015, 11:56:52 AM »
try to add it (without script-tags) into public_html/storefront/view/default/javascript/custom.js and open product page to check it
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline wortman72

  • Newbie
  • *
  • Posts: 11
  • Karma: +1/-0
    • View Profile
Re: Regular Expression help?
« Reply #7 on: June 10, 2015, 12:14:42 PM »
It seems to display the alert whenever that product page is opened.

Offline wortman72

  • Newbie
  • *
  • Posts: 11
  • Karma: +1/-0
    • View Profile
Re: Regular Expression help?
« Reply #8 on: June 10, 2015, 12:35:44 PM »
Does that if statement pull the option value of each option? The option values for option 354 are 785,786,and 787. Option values for 355 are 788, 789, and 790.

If that's the case, it would work if I could make the if statement:  option354 + 3 < option355

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1945
  • Karma: +298/-12
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: Regular Expression help?
« Reply #9 on: June 10, 2015, 01:19:44 PM »
i gave you example with only selected values of selectbox. If you want to get maximum from value set you should to do this by yourself.

Also you can ask stackoverflow.com for this. There are a lot of answers;)
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

 

Powered by SMFPacks Social Login Mod