2

What is wrong with my code. How do i pass attrfull to the inside. The way i have it done, if i run the function editsubmit($selected, size), $selected is inserted properly but i'm getting attrfull instead of size.

function editsubmit(attr, attrfull) {
    if (attr.length) {
        attr.val().length ? $selectedinput.attr({
            attrfull: attr.val()
        }) : $selectedinput.removeAttr(attrfull);
    }
}

$selected is a variable and attrfull i a string. Do i need double qoutes around the string when i run the function like editsubmit($selected,'size').

4
  • Just a thought, but try this: attr(attrfull, attr.val()). Should work... Commented Apr 13, 2011 at 21:31
  • Yes, single quotes or double quotes around the literal strings. Commented Apr 13, 2011 at 21:32
  • I think you should post the code that creates your editsubmit call. It looks like you're using PHP to generate the JS call...which is fine...but we need to see how you construct the edit submit call. Commented Apr 13, 2011 at 21:33
  • attr.val() is the not the issue and i'm not using any php. This is a simple function. The only problem i'm having is attrfull is not being passed in to the attrfull that i have inside the function. So if i have editsubmit($var, 'size'), i'm expecting every reference to attrfull inside the function to be replaced with size. But this is not happening. Commented Apr 13, 2011 at 21:38

3 Answers 3

2

Try

function editsubmit(attr, attrfull) {
    if (attr.length) {
        attr.val().length ? $selectedinput.attr(attrfull, attr.val()) : $selectedinput.removeAttr(attrfull);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

1

Yes, you do need it to be a string (in double quotes), or else it will think you're trying to pass a variable reference.

Comments

1

The problem is this: {attrfull: attr.val()}

I think you want it to be {size: (whatever attr.val() is)}

So:

function editsubmit(attr, attrfull) {
    if (attr.length) {
        if (attr.val().length) {
          var myObj = {};
          myObj[attrfull] = attr.val();
          $selectedinput.attr(myObj);
        } else {
          $selectedinput.removeAttr(attrfull);
        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.