/    Sign up×
Community /Pin to ProfileBookmark

pass javascript variable

Hello All,

I have a website using php, javascript, and html. My php page displays page1.html in the browser. Some text is displayed on the page that the user can edit by clicking on the ‘Edit Status’ button (shown in page1.html code). Clicking on that button calls the edit_status() function in edit_status.js shown below. The edit_status.js file gets a numerical id and text for the user to edit by truncating the text before the brackets {} in the id and name parameters of the input tag in page1.html. The javascript function then displays status_edit.html (shown below) in a pop up window.

The status_edit.html file has a textarea tag in it. I would like to display the text from the javascript file in that textarea and I cannot seem to get it right. Is there a way that I can display the contents of the status_text variable in edit_status.js in the textarea field in status_edit.html??? Thanks in advance!!!

Here is my code:

page1.html:

[CODE]
<html>
<head>
<script type=”text/javascript” src=”js/edit_status.js”></script>
</head>
<body>
<table>
<tr>
<td>”{$status_entry.text}”</td>
</tr>
<tr>
<td>
<input type=”button” id=”edit_status_id_{$status_entry.status_id}” name=”edit_status_text_{$status_entry.text}” value=”Edit Status” onclick=”edit_status(this,’html_files/status_edit.html’)” />
</td>
</tr>
</table>
</body>
</html>
[/CODE]

edit_status.js:

[CODE]
function edit_status(field, url) {
var status_id_full = field.id;
status_id = status_id_full.replace(/^[^0-9]+/, ”);

var status_text_full = field.name;
status_text = status_text_full.replace(‘edit_status_text_’, ”);

// pop up window
window.open(“html_files/status_edit.html”, “Edit Status”, “dependent = 1, status = 1, height = 200, width = 750”);

form.elements[“edit_status_text”].value = status_text; // *note this line*
}
[/CODE]

status_edit.html:

[CODE]
<html>
<head>
<script type=”text/javascript” src=”js/edit_status.js”></script>
</head>
<body bgcolor=”#E6E6E6″>
<form method=”post” name=”updateRisk” action=”update_risk.php?risk_no={$risk.risk_no}” accept-charset=’UTF-8′>
<table>
<tr>
<td bgcolor=”#000099″ align=”center”><font color=”white”><b>Edit Status</b></font></td>
</tr>
<tr>
<td><textarea id=”edit_status_text” name=”edit_status_text” rows=”5″ cols=”87″ wrap=”physical” maxlength=”1500″></textarea></td>
</tr>
<tr>
<td><input type=”submit” name=”save_status” style=”width: 120px” value=”Save Status” /></td>
</tr>
<tr>
<td><input type=”hidden” name=”status_id” value=”{$id}” /></td>
</tr>
</table>
</form>
</body>
</html>
[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @cmartino spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...