0

I have this jQuery code from my previous project and I want to modify it :

<script>
...
$('a.manage-content-link').click(function (e) {
    var self = $(this),
        file = self.siblings('input[type="hidden.block-hidden-input"]').val();
    self.next(".manage-content-wrap").find(".manage-content").load("file-" + file + ".php");
    e.preventDefault();
});
...
</script>

and this HTML code relates to it :

<li>
    <input type="hidden" name="block-type" value="0482" class="block-hidden-input" />
    <input type="hidden" name="sid" value="80132930913019309483" class="block-hidden-input" />
    <a href="#" id="manage-1" class="manage-content-link">
        <img src="images/web-block/web-block1.jpg"/>
        <span class="orange-notice">Click to Edit Content</span>    
    </a>
</li>

<li>
    <input type="hidden" name="block-type" value="1932" class="block-hidden-input" />
    <input type="hidden" name="sid" value="98u40190931209402191" class="block-hidden-input" />
    <a href="#" id="manage-2" class="manage-content-link">
        <img src="images/web-block/web-block2.jpg"/>
        <span class="orange-notice">Click to Edit Content</span> 
    </a>
</li>

and I want to modify that jQuery LOAD part into something like this :

.load("web-block/forms/file-XXX.php?key=YYYYYYYYYYYYYYYY");

where :

XXX = last 3 number from input type="hidden" name="block-type"
example :   0482 >> XXX = 482
            1932 >> XXX = 932

and :

YYYYYYYYYYYYYYYY = value from input type="hidden" name="sid"

please note, for this project I've modified the HTML part so it has 2 hidden inputs. so I believe jQuery selection needs to be modified too... but how?

2
  • why are you using this input[type="hidden.block-hidden-input"]? This is returning undefined for me. It should be like this input[type="hidden"] Commented Oct 27, 2012 at 7:01
  • yes you're right, but how to put the value as XXX and YYYYYYYYY? Commented Oct 27, 2012 at 7:04

2 Answers 2

1
$('a.manage-content-link').click(function (e) {
    var self = $(this),
        file = self.siblings('input[name="block-type"]').val();
    file = file.substring(file.length - 3);
    self.next(".manage-content-wrap").find(".manage-content").load("web-block/forms/file-" + file + ".php?key=" + self.siblings('input[name="sid"]').val());
    e.preventDefault();
});
Sign up to request clarification or add additional context in comments.

1 Comment

You are using incorrect path in .load(). Re-read the question.
1

Use e.preventDefault() at the beginning in un-anonymous function

<li>
<input type="hidden" name="name-block-type" value="0482" class="block-hidden-input" />
<input type="hidden" name="name-sid" value="80132930913019309483" class="block-hidden-input" />
<a href="#" id="manage-1" class="manage-content-link">
    <span class="orange-notice">Click to Edit Content</span>    
</a>
</li>

<li>
<input type="hidden" name="name-block-type" value="1932" class="block-hidden-input" />
<input type="hidden" name="name-sid" value="98u40190931209402191" class="block-hidden-input" />
<a href="#" id="manage-2" class="manage-content-link">
    <span class="orange-notice">Click to Edit Content</span> 
</a>
</li>​

JS

$('a.manage-content-link').click(function (e) {
e.preventDefault();
var self = $(this),
    name = self.parent().find('input[name^=name]').val(),
    lastThree = file.substr(file.length - 3);
self.next(".manage-content-wrap").find(".manage-content").load("web-block/forms/file-" + lastThree + ".php");
});​

2 Comments

bro, there are 2 input[type="hidden"] on each <LI> tag, don't you think we must select specifically by its name for : var lastThree = file.substr(file.length - 3); ?
OK. check my updated answer. check for my html which I modified a bit. I only added name at the beginning of every name attributes.

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.