form submits hrefs images and submit buttons 
Author Message
 form submits hrefs images and submit buttons
hey all,

is there any way that i configure an href="" to work the exact same way as a
submit button, or an image. I know how to make an href="" submit a form, but it
seems to work differently then an input type. In my example the go and the broken
link image will both pop up with the requred fields, but the image wont. Any help
is appreciated.

<table border="5" bordercolor="black">
<tr><td>

<script language="JavaScript">
function validForm(testform)
{
var vInputArray = new Array('field2', 'field3')
var vInputArrayNames = new Array('field 2', 'field 3')
for (var i=0; i<vInputArray.length; i++)
{

if (testform[vInputArray[i]].value=="")
{
alert("You did not fill out the following information: " + vInputArrayNames[i])
return false

Quote:
}
}
}              

</script>

<form name=testform onsubmit="return validForm(this)">
<br><input type="text" name="field1">field 1
<br><input type="text" name="field2">field 2
<br><input type="text" name="field3">field 3
<br><input type="text" name="field4">field 4
<br><input type="submit" value="go!">
<br><a class="Link1" href="javascript:document.testform.submit();"
onclick="javascript:return validForm(this)">Search</a>
<br><input tabindex=14  align="absmiddle" src="submit.gif" type="image">
</form>
</td></tr>
</table>



Sat, 04 Oct 2003 00:42:50 GMT  
 form submits hrefs images and submit buttons
Try to change something below on "onsubmit" and "href".
<form name=testform onsubmit="validForm(this)">
<br><a class="Link1" href="javascript:document.testform.onsubmit();"

Quote:
>Search</a>



hey all,

is there any way that i configure an href="" to work the exact same way as a
submit button, or an image. I know how to make an href="" submit a form, but
it
seems to work differently then an input type. In my example the go and the
broken
link image will both pop up with the requred fields, but the image wont. Any
help
is appreciated.

<table border="5" bordercolor="black">
<tr><td>

<script language="JavaScript">
function validForm(testform)
{
var vInputArray = new Array('field2', 'field3')
var vInputArrayNames = new Array('field 2', 'field 3')
for (var i=0; i<vInputArray.length; i++)
{

if (testform[vInputArray[i]].value=="")
{
alert("You did not fill out the following information: " +
vInputArrayNames[i])
return false

Quote:
}
}
}

</script>

<form name=testform onsubmit="return validForm(this)">
<br><input type="text" name="field1">field 1
<br><input type="text" name="field2">field 2
<br><input type="text" name="field3">field 3
<br><input type="text" name="field4">field 4
<br><input type="submit" value="go!">
<br><a class="Link1" href="javascript:document.testform.submit();"
onclick="javascript:return validForm(this)">Search</a>
<br><input tabindex=14  align="absmiddle" src="submit.gif" type="image">
</form>
</td></tr>
</table>



Sat, 04 Oct 2003 02:51:23 GMT  
 form submits hrefs images and submit buttons
I just read this in Chapter 3 of Beginning JavaScript from WROX Press.
Apparently you can use an event handler to the <A> tag and use a return
value to stop or allow the HREF from firing the hyperlink.

I believe it is something like:

<SCRIPT Language=JavaScript>
    function href_onclick(){
        \\ do something the script may not be fully correct
        document.thisform.submit;            \\ submit the form.
        return false;            \\ stops the href firing.
        return true;            \\ allows the href to fire (may be redundant
after the .submit action).
    }
</SCRIPT>

<A href="Somewhere.asp" onclick="JavaScript:return href_onclick();">Test
Hyperlink</A>

There is a possibility that NN (below version 4) browsers don't support the
HREF onclick() event (I think I read this this afternoon) but there is an
alternative: apparently JavaScrip can 'add' an event handler to the <A> tag
dynamically. Someone may be able to help with this. Failing that, have a
look at the WROX Press site for the download code for Chapter 3 / 4 of
'Beginning JavaScript'.

Chris Barber.


Quote:
> Try to change something below on "onsubmit" and "href".
> <form name=testform onsubmit="validForm(this)">
> <br><a class="Link1" href="javascript:document.testform.onsubmit();"
> >Search</a>



> hey all,

> is there any way that i configure an href="" to work the exact same way as
a
> submit button, or an image. I know how to make an href="" submit a form,
but
> it
> seems to work differently then an input type. In my example the go and the
> broken
> link image will both pop up with the requred fields, but the image wont.
Any
> help
> is appreciated.

> <table border="5" bordercolor="black">
> <tr><td>

> <script language="JavaScript">
> function validForm(testform)
> {
> var vInputArray = new Array('field2', 'field3')
> var vInputArrayNames = new Array('field 2', 'field 3')
> for (var i=0; i<vInputArray.length; i++)
> {

> if (testform[vInputArray[i]].value=="")
> {
> alert("You did not fill out the following information: " +
> vInputArrayNames[i])
> return false
> }
> }
> }
> </script>

> <form name=testform onsubmit="return validForm(this)">
> <br><input type="text" name="field1">field 1
> <br><input type="text" name="field2">field 2
> <br><input type="text" name="field3">field 3
> <br><input type="text" name="field4">field 4
> <br><input type="submit" value="go!">
> <br><a class="Link1" href="javascript:document.testform.submit();"
> onclick="javascript:return validForm(this)">Search</a>
> <br><input tabindex=14  align="absmiddle" src="submit.gif" type="image">
> </form>
> </td></tr>
> </table>



Sat, 04 Oct 2003 03:09:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. SUBMIT form with 3 different submit buttons - error

2. Submitting Form WITHOUT Submit Button

3. form submit using different submit buttons

4. Submitting form without submit button...

5. What fires the submit action of a form without a submit button

6. Submitting Form WITHOUT a Submit Button

7. SUBMIT form with 3 different submit buttons - error

8. Submitting form without submit button...

9. submit button to operate another submit button

10. HOW DO I SUBMIT A FORM WITH AN IMAGE BUTTON

11. submitting form using 2 images as buttons

12. submit without submit button

 

 
Powered by phpBB® Forum Software