Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-13-2011, 11:53 AM   PM User | #1
Albana_12
New Coder

 
Join Date: Dec 2011
Posts: 26
Thanks: 4
Thanked 0 Times in 0 Posts
Albana_12 is an unknown quantity at this point
Javascript problem with a clause?

Thank you!

Last edited by Albana_12; 12-14-2011 at 12:05 PM..
Albana_12 is offline   Reply With Quote
Old 12-13-2011, 03:09 PM   PM User | #2
thesam101
New Coder

 
Join Date: Apr 2010
Location: Norfolk, England
Posts: 63
Thanks: 1
Thanked 14 Times in 14 Posts
thesam101 is an unknown quantity at this point
Hi Albana_12

your script gets the last character of the eventId, so i'm presuming in the original eventId thats passed to it, there is a string before the number? like so:

foo12

for example.

if that's correct, then you can simply run through the characters until they are no longer numbers:

Code:
function wysiwyg_tools_plus_theme_toggleAccordion… {

    var temp = "";
    while(!isNaN(eventId.substring(eventId.length-(temp.length+1), eventId.length)))
    {
	    temp = eventId.substring(eventId.length-(temp.length+1), eventId.length);
    }

    $('#acc-' + temp).toggle('fast');

}
__________________
//Improvement in coding is iterative, each 'failure' is just the next step on your learning curve, some knowledge and logic can get you a long way.//
thesam101 is offline   Reply With Quote
Users who have thanked thesam101 for this post:
Albana_12 (12-14-2011)
Old 12-13-2011, 03:16 PM   PM User | #3
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 961
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
If you're trying to get a string's numeric suffix of any length, you can do this:

eventId = eventId.match( /\d+$/ );
Logic Ali is online now   Reply With Quote
Users who have thanked Logic Ali for this post:
Albana_12 (12-14-2011)
Old 12-13-2011, 09:19 PM   PM User | #4
thesam101
New Coder

 
Join Date: Apr 2010
Location: Norfolk, England
Posts: 63
Thanks: 1
Thanked 14 Times in 14 Posts
thesam101 is an unknown quantity at this point
Quote:
Originally Posted by Logic Ali View Post
If you're trying to get a string's numeric suffix of any length, you can do this:

eventId = eventId.match( /\d+$/ );
Or just do that lol, damn my lack of regex knowledge
__________________
//Improvement in coding is iterative, each 'failure' is just the next step on your learning curve, some knowledge and logic can get you a long way.//
thesam101 is offline   Reply With Quote
Users who have thanked thesam101 for this post:
Albana_12 (12-14-2011)
Old 12-13-2011, 10:57 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,247
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Or, even simpler:
Code:
function wysiwyg_tools_plus_theme_toggleAccordion… 
{
    eventId = eventId.replace(/[^\d]/g, "" );
    $('#acc-' + eventId).toggle('fast');
}
Replace everything in the eventId that is *NOT* a digit with blank string. All that is left is/are the digit(s).
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:58 AM.


Advertisement
Log in to turn off these ads.