I am trying to add an email service to a site. I have a modal message window popping up with Shadowbox (since I had already used Shadowbox on the site for other purposes).
Problem is, I can't seem to pass a variable into my message form that opens up.
I am calling the window thusly
$(document).on("click","#mail",function(e){
e.preventDefault();
var thisParentClass = $(this).parent().attr("class");
alert (thisParentClass);
var thisIDpos = thisParentClass.indexOf("id-")+3;
var thisID = thisParentClass.substr(thisIDpos, 3);
alert(thisID);
Shadowbox.open({
content: '<form method="post" class="mailForm" action="#"><input type="hidden" name="memberID" value=thisID><p>Please be advised that the member may not be actively receiving mail.. or they might just not care at all. They have lives too you know.</p>Your E-mail:<input type="text" name="fromEmail" size="25"> <br>Your Name: <input type="text" name="fromName" size="25"> <br>Your Message: <br><textarea cols="50" rows="5" name="nMessage">Your Message Here...</textarea> <br><button type="submit" onclick="return false;" id="mailSubmit" value="Submit">Submit</button> ',
player: "html",
height: 350,
width: 350,
options: {modal:true}
});
All of my alerts are returning the right values, but [thisID] is not getting into my message form. I just keep getting HTML of 'value="thisID"' (note that the quotes surround my variable regardless of if I add them or not). Is there any way at all to get this variable in, or must I switch to another solution? (I would like my windows to all look the same obviously, so if I can't use Shadowbox here I'll have to change all my implementations. B*tch.
I'm not receiving a registration mail from the Shadowbox forum so I can ask this there for some reason, so I thought I would ask here.
Ideas?
Replace this:
<input type="hidden" name="memberID" value=thisID>
into this:
<input type="hidden" name="memberID" value='+thisID+'>
You need to concatenate the value of thisID into the full string using the + sign.
Full code:
$(document).on("click","#mail",function(e){
e.preventDefault();
var thisParentClass = $(this).parent().attr("class");
alert (thisParentClass);
var thisIDpos = thisParentClass.indexOf("id-")+3;
var thisID = thisParentClass.substr(thisIDpos, 3);
alert(thisID);
Shadowbox.open({
content: '<form method="post" class="mailForm" action="#"><input type="hidden" name="memberID" value='+thisID+'><p>Please be advised that the member may not be actively receiving mail.. or they might just not care at all. They have lives too you know.</p>Your E-mail:<input type="text" name="fromEmail" size="25"> <br>Your Name: <input type="text" name="fromName" size="25"> <br>Your Message: <br><textarea cols="50" rows="5" name="nMessage">Your Message Here...</textarea> <br><button type="submit" onclick="return false;" id="mailSubmit" value="Submit">Submit</button> ',
player: "html",
height: 350,
width: 350,
options: {modal:true}
});