jQuery Help

9 posts by 2 authors in: Forums > CMS Builder
Last Post: August 7, 2014   (RSS)

By claire - August 6, 2014

Hey Perch

You can use the length property of  a string to check if the different variables are set, like so:

if(data1.length < 1) {
    data1 = 'no content';
}

Basically if there's nothing in those fields, the string length will be 0 and this if statement will be triggered.

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Perchpole - August 6, 2014

Hi, Claire -

Thanks for this. The only question is where does it go?!

Should this be used at the top - when assigning a value to a var - or in the $post output?

:0/

Perch

By claire - August 6, 2014

You can add it in just after this line, for whatever variables you want to check.

var data4 = "<?php echo $selectedPageNum; ?>";

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Perchpole - August 7, 2014

Ah! Thanks. It leads nicely to my next question:

Using the example above, how do I pass the value of a radio button array to a var?

:0/

Perch

By claire - August 7, 2014

You can't, as far as I know. Radio buttons only pass one value because they're an either-or selection - you can't choose two radio buttons in the same group. Selecting one deselects whatever you've already chosen.

They usually look something like this:

Choose one:

Option 1: <input type="radio" name="thischoice" value="option1" />
Option 2: <input type="radio" name="thischoice" value="option2" />
Option 3: <input type="radio" name="thischoice" value="option3" />

So when you're getting the value here, the variable will just look like $_REQUEST['thischoice'] and its value will be either option1, option2, or option3.

I'm not sure what you're trying to do, but if you need an array of variables, a list of checkboxes is probably a better idea.

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Perchpole - August 7, 2014

Hi, Claire -

Sorry, I didn't describe it very well. What I want to do is exactly as you have put it. How do I assign the value of "thischoice" to the var?

Perch

By claire - August 7, 2014

Sure - just like this:

var thischoice = $('input[name=thischoice]:checked').val()

--------------------

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Perchpole - August 7, 2014

You star!

Thanks again.

:0)

Perch