...

View Full Version : Javascript problem with a clause?



Albana_12
12-13-2011, 12:53 PM
Thank you!

thesam101
12-13-2011, 04:09 PM
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:


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');

}

:thumbsup:

Logic Ali
12-13-2011, 04:16 PM
If you're trying to get a string's numeric suffix of any length, you can do this:

eventId = eventId.match( /\d+$/ );

thesam101
12-13-2011, 10:19 PM
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 :o

Old Pedant
12-13-2011, 11:57 PM
Or, even simpler:


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).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum