severndigital Posted November 4, 2008 Share Posted November 4, 2008 all i want to do is submit a form when i onblur some text field. i keep getting the error that it's not defined. here is the code i have function submitForm(formName){ document.formName.submit(); } here is the html i am trying to use with that. <form action="?operation=update" method="post" name="ElementForm-1" /> <input name="fontSize" type="text" class="textFormField" size="2" maxlength="3" value="<?php echo $this->_elemFontSize; ?>" onblur="submitForm('ElementForm-1')"/> </form> when i run it i get the error document.formName is undefined anyone help me out?? Thanks, -C Link to comment https://forums.phpfreaks.com/topic/131401-not-sure-why-this-issnt-working/ Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 Is this the only form on the page? If so: function submitForm(){ document.forms[0].submit(); } Link to comment https://forums.phpfreaks.com/topic/131401-not-sure-why-this-issnt-working/#findComment-682405 Share on other sites More sharing options...
severndigital Posted November 4, 2008 Author Share Posted November 4, 2008 it is not the only form on the page. is there no way to submit the form based off of the form's name?? Link to comment https://forums.phpfreaks.com/topic/131401-not-sure-why-this-issnt-working/#findComment-682407 Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 function submitForm(formName){ formName.submit(); } <form action="?operation=update" method="post" name="ElementForm-1" /> <input name="fontSize" type="text" class="textFormField" size="2" maxlength="3" value="<?php echo $this->_elemFontSize; ?>" onblur="submitForm(this.form)"/> </form> Try that. Link to comment https://forums.phpfreaks.com/topic/131401-not-sure-why-this-issnt-working/#findComment-682409 Share on other sites More sharing options...
severndigital Posted November 4, 2008 Author Share Posted November 4, 2008 no good it still tells me formName.submit is not a function it's like it won't reference the formName variable, if that makes sense Link to comment https://forums.phpfreaks.com/topic/131401-not-sure-why-this-issnt-working/#findComment-682413 Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 <form action="?operation=update" method="post" name="ElementForm-1" /> <input name="fontSize" type="text" class="textFormField" size="2" maxlength="3" value="<?php echo $this->_elemFontSize; ?>" onblur="this.form.submit();"/> </form> Link to comment https://forums.phpfreaks.com/topic/131401-not-sure-why-this-issnt-working/#findComment-682418 Share on other sites More sharing options...
severndigital Posted November 4, 2008 Author Share Posted November 4, 2008 sorry .. that's not working either .. there are three forms on the screen, and that way only submits the last of the three ... no matter what field I add the onBlur to Link to comment https://forums.phpfreaks.com/topic/131401-not-sure-why-this-issnt-working/#findComment-682442 Share on other sites More sharing options...
F1Fan Posted November 4, 2008 Share Posted November 4, 2008 <form action="?operation=update" method="post" name="ElementForm-1" /> <input name="fontSize" type="text" class="textFormField" size="2" maxlength="3" value="<?php echo $this->_elemFontSize; ?>" onblur="document.ElementForm-1.submit();"/> </form> Link to comment https://forums.phpfreaks.com/topic/131401-not-sure-why-this-issnt-working/#findComment-682445 Share on other sites More sharing options...
Adam Posted November 5, 2008 Share Posted November 5, 2008 function submitForm(formName){ document.forms[formName].submit(); } replace your function with that.. Link to comment https://forums.phpfreaks.com/topic/131401-not-sure-why-this-issnt-working/#findComment-682825 Share on other sites More sharing options...
JasonLewis Posted November 5, 2008 Share Posted November 5, 2008 Why the old school stuff? There is such thing known as document.getElementById(). Example: <form name="form" id="form" method="post" action="http://www.google.com"> <input type="text" name="textfield" id="textfield" value="onBlur me and I'll go to Google!" onblur="javascript: document.getElementById('form').submit()" /> </form> Link to comment https://forums.phpfreaks.com/topic/131401-not-sure-why-this-issnt-working/#findComment-682856 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.