samedi 18 avril 2015

how to print the id value of a form into the action with javascript

I have a form that submits to the same page, but when the TITLE input changes and the form is submitted, the form is submitted to a page that no longer exists because the TITLE has been changed in the database.


my url is http://localhost/mvc1/content/show_item/title=home


where the form record to be pulled is the TITLE field in the database, so if I change the title to 'Homepage', the form is still submitted to .../title=home


my original action attribute was: action="http://localhost/mvc1/content/show_item/title=home; ?>"


which i changed to action="document.write(document.getElementById('TITLE').value);"


which works fine but only when it comes below the actual TITLE element


if I put the script at the end of the file then the value from the TITLE element appears, but not when I put the script in the action attribute


my form is as follows:



<form name="TABLE_CONTENT" method="POST" action="SCRIPT_DIDN'T_WORK_HERE">
<input type="hidden" name="FORM_NAME" value="TABLE_CONTENT" />
<input type="hidden" name="SUBMITTED" value="SUBMITTED" />
<table border="0" cellpadding="3" cellspacing="0" width="500">
<tr>
<td class="label"><label for="ID">ID</label>:</td>
<td><input type="text" name="ID" value="{$ID}" /></td>
</tr>
<tr>
<td class="label"><label for="TITLE">TITLE</label>:</td>
<td><input type="text" name="TITLE" id="TITLE" value="{$TITLE}" /></td>
</tr>
<tr>
<td class="label"><label for="CONTENT">CONTENT</label>:</td>
<td><textarea name="CONTENT">{$CONTENT}</textarea></td>
</tr>
<tr>
<td class="label"><label for="URL">URL</label>:</td>
<td><input type="text" name="URL" value="{$URL}" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="submit" name="SUBMIT" value="Edit" />
</td>
</tr>
</table>
</form>


I'm sure this is actually a pretty common problem when a form submits to iteself, but I haven't been able to figure this one out, I'm assuming I need a javascript function with an onchange attribute on the title="Home" element but I have little experience with javascript and haven't been able to find anything that I can make work on my own, thanks for the help


Aucun commentaire:

Enregistrer un commentaire