I have a table generated by php and implementing a modal to allow user to change the text generated by variable $l_id; I have a link class “eloc” that show’s the modal div section. I intercept the form submit id “renameLocation” and process the input and disable the default submit action. I want to modify show the new text renamed by the user.
I have this php code which repeated by iterating an array, the iteration id is $l
$id_l="\"location_".$l."\"";
echo "<table class=\"add\" border=\"1px\" width=\"100%\">";
echo "<tr class=\"header\"><td class=\"stretch\"><a class=\"eloc\" rel=\"leanModal\" href=\"#modal_location\"><img src=\"images/edit-icon.png\" alt=\"Location\"></a></td><td id=\"".$id_l."\" class=\"location\" colspan=\"6\">Location: ".$row['location']."</td></tr>";
Then I have a div:
<div id="modal_location" class="modal_prompt">
<div class="modal_prompt-ct">
<div class="modal_prompt-header">
<h2>Rename Location</h2>
<a class="modal_close" href="#"></a>
</div>
<form id="renameLocation">
<div class="txt-dpy">
<span id="mlocation_name"></span>
</div>
<div class="txt-fld">
<label for="">Change to</label>
<input id="newLocation" name="" type="text" />
</div>
<div class="btn-fld">
<button type="submit">Save »</button>
</div>
</form>
</div>
</div>
How to modify the text for the generated $l_id?
$("#renameLocation").submit(function(e)
{
$("#lean_overlay").fadeOut(200);
$("#modal_location").css({"display" : "none" })
// How to modify the text of "$l_id"?
return false; //do not submit form the normal way
});
Many thanks.
Question is ambiguous. It sounds like you have more than one text to edit.
You need a way to tell JS which location to update so add a global variable. It’s not usual way you’d do this but it should be okay.
Add data to the element
set this at the top of your js
bind clicking the edit link to set selectedlocation
use the var in your code
Here’s another way
Forget the global variable.
Add a hidden form field
Put the value in that
And use that.
The way you have provided it, the modal is totally independant to the links you need something to set somewhere to achieve what you want.