How do I send a javascript variable to a subsequent jquery function or set of braces?
Posted
by desbest
on Stack Overflow
See other posts from Stack Overflow
or by desbest
Published on 2010-05-10T14:09:16Z
Indexed on
2010/05/10
14:14 UTC
Read the original article
Hit count: 210
How do I send a javascript variable to a subsequent jquery function? Here is my code.
<script type="text/javascript">
$(function() {
var name = $("#name"),
email = $("#email"),
password = $("#password"),
itemid = $("#itemid"),
tips = $(".validateTips");
function updateTips(t) {
tips
.text(t)
.addClass('ui-state-highlight');
setTimeout(function() {
tips.removeClass('ui-state-highlight', 1500);
}, 500);
}
$("#dialog-form").dialog({
autoOpen: false,
height: 320,
width: 350,
modal: true,
/*
buttons: {
'Change category': function() {
alert("The itemid2 is "+itemid2);
var bValid = true;
$('#users tbody').append('<tr>' +
'<td>' + name.val() + '</td>' +
'<td>' + email.val() + '</td>' +
'<td>' + password.val() + '</td>' +
'<td>' + itemid.val() + '</td>' +
'</tr>');
$(this).dialog('close');
},
Cancel: function() {
$(this).dialog('close');
}
},
*/
close: function() {
allFields.val('').removeClass('ui-state-error');
}
});
$('.changecategory')
.button()
.click(function() {
var categoryid = $(this).attr("categoryid");
var itemid = $(this).attr("itemid");
var itemid2 = $(this).attr("itemid");
var itemtitle = $(this).attr("itemtitle");
var parenttag = $(this).parent().get(0).tagName;
var removediv = "itemid_" +itemid;
alert("The itemid is "+itemid);
$('#dialog-form').dialog('open');
});
});
</script>
I'll break it down.
- The .changecategory section happens FIRST when an image on my page is clicked.
- $("#dialog-form").dialog({ is then called, and the variable item id is not passed to this function. How can I pass a variable from one function to another? Is that possible.
Is there a way I can pass a variable to another jquery function without having to resort of setting a cookie with javascript and then using jquery to read it?
© Stack Overflow or respective owner